Print All Odd Numbers Between 1 and 100
List odd numbers below one hundred using range. Beginners compare start, stop, and step and check the last printed value without an extra parity condition.
1# Print odd numbers from 1 to 1002for i in range(1, 101, 2):3 print(i)
Output
...
The sample abbreviates a longer result. The program prints the intervening values; it does not print these dots.
In this one
- Generate odd terms directly
- Separate stop from last value
- Count range iterations
How it works
- 1
Start at one with step two.
- 2
Stop before 101.
- 3
Print each visited odd value.
Edge cases
Is 101 printed?
Is 101 printed?
No. It is the excluded stopping value.
Is 100 printed?
Is 100 printed?
No. It is even and never reached by this step.
What's going on
The sequence starts at one and increases by two. Every visited value is odd, so there is no if statement inside the loop.
The stopping value is 101 and is excluded. The last printed number is therefore 99, not 100 or 101. Each iteration uses print's default newline, making the fifty values appear on separate lines.
Is 101 printed? No. It is the excluded stopping value.
Is 100 printed? No. It is even and never reached by this step.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which range parameter skips evens?
Pick an answer to check it.
Question 2
Is 101 printed?
Pick an answer to check it.
Questions people ask
Is 101 printed?
No. It is the excluded stopping value.
Is 100 printed?
No. It is even and never reached by this step.
Which range parameter skips evens?
The step of two.
๐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