How to check for Even and odd Numbers in Python ?
How to check for Even and odd Numbers in Python ?
In this blog post, you will learn to check whether a number entered by the user is even or odd.
A number is even if it is divisible by 2 . When the number is divided by 2, we use the remainder operator %
to compute the remainder. If the remainder is zero, the number is even else the number is odd.
# How to check for Even and odd Numbers in Python ?
num = int(input("Enter any number:"))
if (num % 2) == 0:
print('This is an EVEN number!')
else:
print('This is an ODD number!')
Output 1:
Enter any number:4
This is an EVEN number!
This is an EVEN number!
Output 2:
Enter any number:16
This is an EVEN number!
This is an EVEN number!
Output 3:
Enter any number:13
This is an ODD number!
This is an ODD number!
Leave a Comment