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

print("Enter 'x' for exit.");
num = input("Enter any number: ");
if num == 'x':
    number = int(num);
except ValueError:
    print("Please, enter a number...");
    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:

find reverse of number python

When you run the above program, then you will see the above sample output asking from the user to enter that number, whose reverse he/she want to see. Therefore let's enter any number say 123 to see what will be its reverse as shown in the below sample output:

reverse of number python

Here is the same program with run on python shell:

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 »


Quick Links
Signup - Login - Give Online Test