Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started