Odd number

Opposite of even numbers, odd numbers are having a difference of 3 unit or number. In other words, if the number is not completely divisible by 2 then it is an odd number.

Logic

The logic for printing odd numbers are pretty simple and straight forward, we only need to check if the number is not divisible by 2. If the number is not divisible by 2, then we have to print it.

Program

# Take input from user
num = int(input("Print all odd numbers till : "))

print("\nOdd numbers from 1 to", num, "are : ")

for i in range(1, num + 1):

    #Check for odd or not.
    if((i % 2) != 0):
        print(i, end=" ")

Output

Print all odd numbers till : 50
Odd numbers from 1 to 50 are :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49