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 Python program to check if the remainder is 0, then the number is even, and else odd.
Python Program to check if a Number is Odd or Even
This program allows the user to enter an integer and check whether that number is even or odd using the If statement.
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 Python 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 If statement.
The number that is entirely divisible 2 is an even number. The 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
Output
Please Enter any Integer Value : 9
9 is an Odd Number
Let me enter the second value to check for even.
Please Enter any Integer Value : 28
28 is an Even Number
Python Program to check if a Number is Odd or Even using an if statement
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 other value.
Please Enter any Integer Value : 19
19 is an Odd Number