Print All Even Numbers Between 1 and 100
Generate even numbers from two through one hundred in Python. Students use a range step of two and learn why the stop must be beyond the final desired value.
1# Print even numbers from 1 to 1002for i in range(2, 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 only even terms
- Use a nonunit step
- Include a desired endpoint
How it works
- 1
Start the range at two.
- 2
Advance by two while staying below 101.
- 3
Print every supplied even value.
Edge cases
Is zero included?
Is zero included?
No. The sequence starts at two.
Is one hundred included?
Is one hundred included?
Yes. It is reached before the excluded stop 101.
What's going on
Starting at two and advancing by two visits only even numbers. The loop does not generate odds and filter them afterward.
range(2, 101, 2) includes one hundred but excludes the stop 101. Each print writes one selected value on a new line. There are fifty iterations, so changing the step affects both the values and the number of printed lines.
Is zero included? No. The sequence starts at two.
Is one hundred included? Yes. It is reached before the excluded stop 101.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What is the step?
Pick an answer to check it.
Question 2
Is zero included?
Pick an answer to check it.
Questions people ask
Is zero included?
No. The sequence starts at two.
Is one hundred included?
Yes. It is reached before the excluded stop 101.
What is the step?
2.
๐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