Question: sum = 0 for i in range(2,134): sum = sum+1 a. Modify the code, instead of using a for loop, use a list comprehension. Use
sum = 0
for i in range(2,134):
sum = sum+1
a. Modify the code, instead of using a for loop, use a list comprehension. Use the variable i as the indexer in the list comprehension and apply the function sum() to the list.
My answer: sum(i for i in range(2,134)) is wrong. I don't know how to fix it.
b. Modify your code from part (a). Sum up the squares of the integers instead of just the integers. What is the result?
My answer: sum(i**2 for i in range(2,134)) is wrong.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
