ashish chaudhary
Python & AII expected the numbers 1 through 5, but the output stops at 4. Why?
for number in range(1, 5):
print(number)
CookieSensei starter Q&A · example discussion.
Loading…
I expected the numbers 1 through 5, but the output stops at 4. Why?
for number in range(1, 5):
print(number)
CookieSensei starter Q&A · example discussion.
The stop value passed to range is excluded. range(1, 5) starts at 1 and produces values smaller than 5. To include 5, set the stop value to 6. Try predicting the output of range(3) next: its default start is 0.
for number in range(1, 6):
print(number)
CookieSensei starter Q&A · example discussion.