In this Python program, we will learn how to check if a given number is odd or even.
A Number is Even if it is perfectly divided by 2 and the remainder equals 0 and a number is Odd if the remainder does not equal 0. To Calculate the remainder, we use the % operator.
Here is the source code of the program to check if a given number is odd or even.
# Python Program to Check if a Given Number is Odd or Even
# A number is even if division by 2 gives a remainder equals to 0.
# If the remainder is 1, it is an odd number.
# Take the input from the User
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("\n{0} is Even Number".format(num))
else:
print("\n{0} is Odd Number".format(num))
Enter a number: 5
5 is Odd Number
Enter a number: 6
6 is Even Number
Comments