Python Program to Check If a Number is Odd or Even
ADVERTISEMENTS
Python program to check if a number is odd or even using an if-else statement.
In this article, you will learn how to make a python program to check if a number is odd or even using an if-else statement.
Example
Enter an integer number to check:
34
The input number is even.
34
The input number is even.
What are even odd numbers?
There is if any integer number divided by 2 and its remainder equals zero then it is an even number and if the remainder is greater than zero then it is an odd number.
Samples of even odd Numbers
Even Numbers: 0, 2, 4, 6, ...
Odd Numbers: 1, 3, 5, 7, ...
Source Code
# Python Program to Check If a Number is Odd or Even using If-else Statement
print ("Enter an integer number to check:\n")
x = int (input ())
if (x % 2 == 0):
print ("The input number is even.\n")
else:
print ("The input number is odd.\n")
Output
Enter an integer number to check:
34
The input number is even.
Explanation
In this given program, we have taken input 34
from the user then It will find the reminder by using the value 2
on this input If the reminder is equal to 0 It's an even number otherwise this is the odd number
- m = 34 % 2, if m=0 then even number otherwise odd number
Python Program to Check If a Number is Odd or Even using Ternary Operator
# Python Program to Check If a Number is Odd or Even using Ternary Operator
print ("Enter an integer number to check:\n")
x = int (input ())
x = 1 if x % 2 == 0 else 0
if (x):
print ("The input number is even.\n")
else:
print ("The input number is odd.\n")
Output
Enter an integer number to check:
35
The input number is odd.