A Day at the Supermarket 3


#1

Good Afternoon Ladies and Gents I have a problem in the 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
    elif number % 2 != 0:
     break

I get this error message:Oops, try again. Your code should have printed 2, but did not!


#2

why do you have an elif? You just want to print out even numbers, your if statement is doing this


#3

Yes i have an elif that is the whole code


#4

that was not the question i asked, i asked why do you have it? Your if statement will print out all the even numbers as the exercise desires of you, so what do you still need an elif for?


#5

Sorry are you asking why I have it or are you asking what I should use it for?


#6

@stetim94 meant that you don't need elif block for this exercise


#7

Oh ok I didn't understand the context he was using thank you both, Have a nice day!


#8

@coreninja17109 gets it, your if block already does all the work required for the exercise, you don't need your elif, i hoped by asking this question you would take time to think the purpose your elif served, and then come to the conclusion you don't need it