codescracker


python

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
		
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:

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 »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test