+ 1
How do you solve 27.2 iteration I don't understand
I don't know how to sum lists this my code for now it give me unexpected indent list = [1, 2, 3, 4, 5, 6, 7, 8, 9] count = 0 for x in list: count=list+x print(count)
2 Answers
+ 6
Don't indent line 2 and 3. Instead indent line 4 (this belongs into the for-loop) and change line 4 for count = count + x (you want to add x to the count)
0
Well, I hope this will help you out. I went back out previous lesson 26.6 Practice Free Stuff! if you look at the code it add the even number in the list. So it deducing what will add all the number in the list. Here my code.
list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sum = 0
#your code goes here
n = 0
while n < len(list):
num = list[n]
n += 1
if (num == 0):
continue
sum += num
print(sum)
You take the %2 out and change the == 1 to 0.
It will add all the number in the list. Remember %2 looks for even numbers in the list.. Hope help.