Python Program to Reverse a Given Number

In this example, we will write a simple program to take input number from the user and display it in a reverse way. To better understand this example, make sure you have knowledge of the following tutorials:-

Loading...

Python Program to Reverse a Given Number

number = int(input("Enter the number to reverse: "))
reverse = 0
while number > 0:
    dig = number % 10
    reverse = reverse * 10 + dig
    number //= 10
print("The Reverse of the number:", reverse)

The output of the above program is:-

Enter the number to reverse: 12345
The reverse of the number: 54321
Loading...
SHARE Python Program to Reverse a Given Number

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Share