Python Program to Print Odd Numbers In A Given Range

This program prints all odd numbers in a given range by user in Python language.

In this Python program, we first read min_value and max_value from user. Then we print all odd numbers using for loop and if statement.

Python Source Code: Odd Numbers


# Print odd numbers in range

min_value = int(input("Enter minimun of range: "))
max_value = int(input("Enter maximun of range: "))

print("\nOdd numbers from %d to %d are: " % (min_value, max_value))
for i in range(min_value, max_value+1):
    if(i%2==1):
        print(i, end=" ")

Output

Enter minimun of range: 23
Enter maximun of range: 68

Odd numbers from 23 to 68 are: 
23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67