Even number

Even number are numbers that have a difference of 2 unit or number. In other words, if the number is completely divisible by 2 then it is an even number.

Logic

This program is similar to the previous one the only thing different here is, here we have to check if the number is completely divisible by 2 or not.

If the number is divisible by 2 then it is an even number, simply print it.

Program

# Taking input from user
num = int(input("Enter any number : "))

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

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

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

Output

Print all even numbers till : 50
Even numbers from 1 to 50 are :
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50