Print Numbers from 10 Down to 1
Count backward from ten to one with Python range. Students trace a negative step, an excluded lower stop, and why the direction of a range must match its step.
1# Print numbers 10 to 12for i in range(10, 0, -1):3 print(i)
Output
10 9 8 7 6 5 4 3 2 1
In this one
- Choose a negative step
- Read descending bounds
- Exclude the lower stop
How it works
- 1
Start i at ten.
- 2
Decrease it by one while above zero.
- 3
Print each value before the next step.
Edge cases
Is zero displayed?
Is zero displayed?
No. The loop ends before its stop value.
What if the step were positive one?
What if the step were positive one?
The range would be empty for these bounds.
What's going on
A negative step makes i decrease after each iteration. range(10, 0, -1) begins at ten and stops before reaching zero.
The ten values print on ten lines. The stop is still excluded even though the direction is reversed. A positive step with these same bounds would produce no values, because it could never approach the lower stop.
Is zero displayed? No. The loop ends before its stop value.
What if the step were positive one? The range would be empty for these bounds.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which value is printed last?
Pick an answer to check it.
Question 2
Is zero displayed?
Pick an answer to check it.
Questions people ask
Is zero displayed?
No. The loop ends before its stop value.
What if the step were positive one?
The range would be empty for these bounds.
Which value is printed last?
1.
๐Related Content
- ๐
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- ๐
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- ๐ป
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum