To check whether the given number is an even number or an odd number in python, you have to ask from user to enter a number to check for even or odd as shown in the program given below.
Following python program ask from user to enter any number to check whether it is an even or an odd number:
# Python Program - Check Even or Odd while True: print("Enter 'x' for exit.") num = input("Enter any number: ") if num == 'x': break try: number = float(num) except ValueError: print("Please, enter a number...") else: check = number%2 if check == 0: print(int(number), "is even number.\n") elif check == 1: print(int(number), "is odd number.\n") else: print(number, "is strange.\n")
Here is the sample run of the above Python program shows how to check for even or odd:
You may also like to learn or practice the same program in other popular programming languages: