Python program to check if a number is odd or even

Python program to check if a number is even or odd.

Python program to check if a number is odd or even
Check if a number is odd or even in Python

If a number is divisible by 2, it is even, else, it is odd. You can use the modulus operator % to compute the remainder. If the remainder is not zero, the number is odd.

Example 1

Code

num = 12

if num%2 == 0:
    print("It is even")
else:
    print("It is odd")

Output

It is even

Example 2 - Asking for user input

Code

num = int(input("Enter a number ==> "))

if num%2 == 0:
    print("It is even")
else:
    print("It is odd")

Output

Enter a number ==> 9
It is odd

The above code uses the input() function to ask for user input.

Subscribe to Pylenin

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe