13. for your lists


#1



https://www.codecademy.com/courses/python-beginner-en-cxMGf/1/5?curriculum_id=4f89dab3d788890003000096#


My code works fine I just have a simple question about modifying the code:
If I wanted to SUM all of the lines that get printed, how would I go about doing that?

i figured it would be as simple as:

print sum(num ** 2) but this does not work. May I please have some guidance on such a simple task?


numbers  = [7, 9, 12, 54, 99]

print "This list contains: "

for num in numbers:
    print num

# Add your loop below!
for num in numbers:
    print num ** 2


#2

but then you would do simple:

numbers =  [7, 9, 12, 54, 99]
print sum(numbers)

right?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.