3/10 A Day at the Supermarket (Solved)


#1

Code:

a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

for number in a:
    if number % 2 == 0:
        print number

OutPut:

File "python", line 3
    for number in a:
      ^
SyntaxError: invalid syntax

I can't figure out where I'm going wrong. I change "number" in the for loop, but nothing sticks. Thanks for the help.


#2

[ needs to be matched with a ]

The caret ^ is pointing at where it stops making sense, that isn't necessarily where the mistake is.

edit: it's not spelled "carrot" <.<


#3

Thanks a lot for the help


#4

a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

for i in a:
if i % 2 == 0:
print i


#5

don't forget your indention of the 'print' after the "if" statement.
The correct code should look like this

a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

for number in a :
if number % 2==0 :
print number