Python Program to print all Odd Numbers in a range

Problem: Write a python program to print all odd numbers within a given range.

Solution: This python program accepts a lower and upper limit of range. For each number in the range it checks whether the number is divisible by 2 or not. If it divisible by 2 it is not an odd number else it is a odd number.

Python program to print all odd numbers in given range

start=int(input("Enter lower limit: "))
end=int(input("Enter upper limit: "))
for num in range(start,end+1):
    if(num%2!=0):
        print(num, end=" ")

Note: end parameter specifies the string or character with which to end the contents passed to print() function. end=" " means end the output with a space. By default value of end parameter is '\n'.

Output:

Enter lower limit: 1
Enter upper limit: 10

1 3 5 7 9