Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

9. What is the mean life span of an olfactory receptor?

Answered: 1 week ago