Python program to find the reverse of a given number
Write a Python program to accept a number from the user, find and display the reverse of a given number.
Video Tutorial
Example:
Let the user has entered the number 123. Then the procedure to find the reverse of a number is given below.
num = 123 rev = 0
Iteration 1
rem = num % 10 = 123 % 10 = 3
rev = rev * 10 + rem = 3
num = num //10 = 123 // 10 = 12
Iteration 2
rem = num % 10 = 12 % 10 = 2
rev = rev * 10 + rem = 30 + 2 = 32
num = num //10 = 12 // 10 = 1
Iteration 3
rem = num % 10 = 1 % 10 = 1
rev = rev * 10 + rem = 320 + 1 = 321
num = num //10 = 1 // 10 = 0
Source code of Python program to find the reverse of a given number
num = int (input("Enter the number: ")) org = num rev = 0 while num > 0: rem = num % 10 rev = rev * 10 + rem num = num // 10 print ("The rverse of ", org, "is ", rev)
Output:
Case 1:
Enter the number: 321
The rverse of 321 is 123
Case 2:
Enter the number: 1234321
The rverse of 1234321 is 1234321
Summary:
This tutorial discusses how to write a Python program to find the reverse of a given number. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.