0
Help me please with “for” in Python
Name list of numbers print their sum. The last line, when displayed, shows the amount. How to display only the last row and not all? list = [1, 2, 3, 4, 5, 6, 7, 8, 9] sum = 0 for n in list: sum = n + sum print(sum)
6 Answers
+ 3
remove the indentation before the print statement :)
+ 2
your print is inside for loop.
And You can also use this
a = [1,3,5,90]
print(sum(a))
+ 1
the "print(sum)" line is indented one block too much.
unindent it so its on the same level as the start of the for loop and it will only print the final sum.
** you have the call to print INSIDE the for loop, all you gotta do is take it out
+ 1
Alexander, thank you, its working!
0
Hi! Please, show us your efforts for better help
0
3
6
10
15
21
28
36
45