Python program to find whether a given number is even or odd
A number is said to be even if any number is completely divisible by 2, which means there is no remainder left or it is zero. If there is any remainder left, the number will be odd. We will use the remainder operator while dividing the number by 2 to get the remainder.
Example: 2, 3, 6 …. are even numbers, and 3, 5, 7… are odd numbers.
The following is the source code to check even or odd number:
#Program to check a given number is even or not #Take input from user number = int(input("Enter the number to be checked:")) # Check the number to even or odd if (number % 2) == 0: print(number, "is an even number.") else: print(number, "is not an even number.")
In this program, a user will be asked to enter the input that will be stored in a number variable. Next, the input number is divided by 2, and by using the IF statement, it will check the remainder is zero or something else. If the remainder is zero, the number is even. If the remainder is other than zero, the number is odd.