[Python]Loops -For your health


here is the instruction:
Make the loop print the numbers from 0 to 19 instead of 0 to 9.

print "Counting..."

for i in range(10,20):
    print i

so i print 10 to 19
and the wrong message showed

I t looks like your code does not print 20.

so i changed the code below:

print "Counting..."

for i in range(10,21):
    print i

the wrong message showed

Make sure you stop at 19!

what a wrong comprehension i have?






Ha, haven't seen that one before (been around a while)

The submission test is trying to pull off something rather questionable:

if not all(CC.printed(str(i)) for i in range(20)):
    return "It looks like your code does not print %s." % str(i + 1)

So it loops through range(20), checking each value - so far it's correct. But then it assumes that i will have been defined by that loop, but that loop runs in a separate scope, so what i is actually referring to, is what you assigned to it last. Your value for i is 19 after your loop, and it adds 1 and ends up saying you didn't print 20.

What they tried to do was fancy, very questionable, and just didn't work.

Anyway. As you said. It should print 0 to 19. You're not.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.