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 print("Enter 'x' for exit."); num = input("Enter any number: "); if num == 'x': exit(); try: number = float(num); except ValueError: print("Please, enter a number..."); else: check = number%2; if check == 0: print(int(number), "is an even number."); elif check == 1: print(int(number), "is an odd number."); else: print(number, "is strange.");
Here is the sample run of the above Python program shows how to check for even or odd:
This is the initial output asking from the user to enter any number:
Now let's first type any odd number say 27 and press enter key to see the following sample output:
Now this time, let's check for even number just by typing any even number say 20 and press enter to see the following output:
Here is the same program written and run on python shell.
You may also like to learn or practice the same program in other popular programming languages: