Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is the code Use list comprehension to find the sum of all numbers that are divisable by 3 between and an upper limit n.

image text in transcribed
Below is the code
image text in transcribed
Use list comprehension to find the sum of all numbers that are divisable by 3 between and an upper limit n. If you are struggling, write this in a more "traditional" format first and then convert it to list comprehension. You should update the function sum_div_ 3(n) so that it returns the correct sum. def sum_div_3( n ): "I" you should update div_by_3_list to generate the list of numbers div by 3 and return their sum. e.g. for n=10 it should look at 1,2,3,4,5,6,7,8,9,10 and the list should contain [3,6,9]. The function should then return the list sum, in this case 18 "n" div_by_3_list = [] return sum(div_by_3_list) if name__= "_main_" : print(sum_div_3(10)) print(sum_div_3(12)) print(sum_div_3(100))

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

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago