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.
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': exit(); 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:
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:
Here is the same program with run on python shell:
You may also like to learn or practice the same program in other popular programming languages: