Write a Python Program to check if a Number is Odd or Even using the If Statement with an example. As we all know, If the number is divisible by 2, then we call it even. And the remaining ones (not divisible by 2) are called odd numbers.
In Python, we have an Arithmetic Operator called % (Modulus) to see the remainder. Let’s use this arithmetic operator in this program to check if the remainder is 0, and then the number is even, and else odd.
Python Program to check if a Number is Odd or Even using If Else
This program allows the user to enter an integer and check whether that number is even or odd using the If statement. For more examples, refer to the Python Basic Programs.
number = int(input(" Please Enter any Integer Value : "))
if(number % 2 == 0):
print("{0} is an Even Number".format(number))
else:
print("{0} is an Odd Number".format(number))
Within this odd or even program, the below statement asks the user to Enter any integer value.
number = int(input(" Please Enter any Integer Value : "))
In the Next line, We declared the Python If statement.
The number that is entirely divisible 2 is an even number. The Python Arithmetic Operator inside the Python If condition checks the same.
- If the condition is True, then it is an Even
- If the condition is False, then it is an Odd
First, Let me enter 9 to check the Else block, and for the second time, enter 28 to check the even number.

Python Program to check if a Number is Odd or Even using Ternary Operator
In this odd or even program example, we are using the if statement in a single line.
number = int(input(" Please Enter any Integer Value : "))
print("{0} is an Even Number".format(number)) if(number % 2 == 0) else print("{0} is an Odd Number".format(number))
Let me try the multiple values.

Program to check even or odd using the bitwise AND operator
We can use the Bitwise AND operator (&) in an if-else statement to check whether the given number & 1 equals 0. If it is, the number is even. Otherwise, it’s an odd number. Refer to Python Bitwise operators.
13 & 1
1101 & 0001 = 1, so it’s an odd number. n = 13
if n & 1 == 0:
print("Even Number")
else:
print("Odd Number")
Odd Number
Even or odd program using functions
In the program below, we defined a function that accepts a number and uses the modulo operator to check whether it is even or odd.
def check_even_odd(x):
if x % 2 == 0:
return f"{x} is Even"
else:
return f"{x} is Odd"
n = int(input("Enter the number : "))
print(check_even_odd(n))
Enter the number : 19
19 is Odd
Enter the number : 24
24 is Even
Use a lambda function to find even or odd
Here, the Python lambda expression accepts a number and checks whether it is divisible by 2. If true, Even; otherwise, odd.
eo = lambda n: "Even" if n % 2 == 0 else "Odd"
num = int(input("Enter the number : "))
print(eo(num))
Enter the number : 15
Odd
Enter the number : 90
Even
Check multiple numbers for even and odd
If our task is to check multiple numbers in a list for even and odd, we can use a list comprehension. The for loop in a Python list comprehension iterates over a list of numbers. Next, the if statement checks whether each iteration number is divisible by 2. If true, print it as even. Otherwise, print it as an odd number.
values = [2, 5, 9, 12, 15, 18, 20, 25]
eo = [f"{n} is Even" if n % 2 == 0 else f"{n} is Odd" for n in values]
for e in eo:
print(e)
2 is Even
5 is Odd
9 is Odd
12 is Even
15 is Odd
18 is Even
20 is Even
25 is Odd
Also Read