codescracker


python

Python Program to Find Reverse of Number



« Previous Program Next Program »


Find Reverse of Number in Python

To find reverse of a number in python, you have to ask from user to enter a number and then reverse that number to print the reversed number as output as shown here in the program given below.

Python Programming Code to Find Reverse of Number

Following python program ask from user to enter a number to find and print reverse of the number:

# Python Program - Find Reverse of a Number
		
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:
		rev = 0
		while number > 0:
			rev = (rev*10) + number%10
			number //= 10
		print("Reverse of entered number =",rev)

Here is the sample run of the above python program to illustrate how to find and print reverse of any number:

python find reverse of a number

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