Print Odd Numbers in Range

Print all odd numbers between 1 and a given upper limit.

BeginnerTopic: Loop Programs
Back

Python Print Odd Numbers in Range Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# Program to print odd numbers up to N

n = int(input("Enter upper limit: "))

for i in range(1, n + 1, 2):
    print(i)
Output
Enter upper limit: 10
1
3
5
7
9

Understanding Print Odd Numbers in Range

We start from 1 and step by 2 with range(1, n + 1, 2) to generate all odd numbers <= n.

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.

Table of Contents