codescracker


python

Python Program to Check Reverse Equals Original or Not



« Previous Program Next Program »


Check Reverse Equals Original in Python

To check whether the original number is equal to its reverse or not in python, you have to ask from user to enter the number and start reversing that number. After find the reverse of the given number, check whether the reverse is equal to the given number or not as shown in the program given below.

Python Programming Code to Check Reverse Equals Original

Following python program ask from user to enter any number to check whether it is equal to its reverse or not:

# Python Program - Check Original Equals Reverse or Not
		
while True:
	print("Enter 'x' for exit.")
	num = input("Enter any number: ")
	if num == 'x':
		break
	try:
		number = int(num)
	except ValueError:
		print("Please, enter a number...")
	else:
		orig = number
		rev = 0
		while number > 0:
			rev = (rev*10) + number%10
			number //= 10
		if orig == rev:
			print("Original number is equal to its reverse.\n")
		else:
			print("Original number is not equal to its reverse.\n")

Here is the sample run of the above Python program demonstrating how to check whether original number is equal to its reverse or not:

python check reverse equals original

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