Control Flow and Looping


#1



Replace this line with your code. 
 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
for number in a:
    if number % 2==0:
       print a
Error message:
Oops, try again. Your code should have printed 0, but did not!


#3

thank you so much..it's work well


#4

can u plz tell wats wrong in ur above code?? ...I'm also getting the same error


#5

Hi, there is nothing wrong with your code. I don't know but the website inerpreter is unable to identify your code.
You can try a second approach based upon list index.
here is the code for that.
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

for i in range(13):
if a[i] %2==0:
print a[i]

Remember your code was absolutly fine


#6

thnku so mch........i hv solved it..:slight_smile:
:relaxed:


#7

'print number' not 'print a'
should work


#8

Can anyone shed some light on why tests like %2 == 0 are used? I mean, even numbers/2 doesn't actually equal 0! Thanks :slight_smile:


#9

I can 't solved it with this solution. What I do wrong?

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

for i in range(13):
if a[i] %2==0:
print a[i]


#10

you should print "number" instead of "a"


#11

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

for i in range(13):
if number[i] %2==0:
print number


#12

Your Code is wrong.

I used numb. You can use anything.

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

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

#13

thank you for your help !


#14

Thank you.
I almost started to cry! You saved my tears! :slight_smile: