In this post, we will write a Python program to check whether the number entered by user is even or odd.
Example: Check If number is even or odd
This program takes the input from user and checks whether the entered number is even or odd. We are receiving the value into a variable
num and then we are dividing the
num by 2 to see whether it is an even number or odd number.
num = int(input("Enter any number: ")) flag = num%2 if flag == 0: print(num, "is an even number") elif flag == 1: print(num, "is an odd number") else: print("Error, Invalid input")
Leave a Reply