230k views
2 votes
For number in range(5):

if number % 2 == 0:
print("even")
else:
print("odd")


# Should print:
# odd
# even
# odd
# even
# odd

User Mbajur
by
7.6k points

1 Answer

4 votes

Answer:

The way the range( ) function works, number goes from 0 to 4, excluding 5. So it will print:

even

odd

even

odd

even

So your expectation is incorrect, or your implementation is incorrect. If you want to test numbers 1 through 5, you could change the first line of the code to:

for number in range(1,6):

User OpenSource
by
8.1k points

No related questions found