Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

BeginnerPhase 2 - Level 1: Basic LoopingExample 5 of 14
print-all-odd-numbers-between-1-and-100.py
1# Print odd numbers from 1 to 100
2for 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. 1

    Start at one with step two.

  2. 2

    Stop before 101.

  3. 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.