Python Program to Check Even or Odd

« Previous Program Next Program »

Check Even or Odd in Python

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.

Python Programming Code to Check Even or Odd

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':
    number = float(num);
except ValueError:
    print("Please, enter a number...");
    check = number%2;
    if check == 0:
    	    print(int(number), "is an even number.");
    elif check == 1:
    	print(int(number), "is an odd number.");
    	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:

check even odd python

Now let's first type any odd number say 27 and press enter key to see the following sample output:

check odd even python

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:

python check even odd program

Here is the same program written and run on python shell.

python check even or odd

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test