Python Program to Reverse a Given Number
Python Program to Reverse a Given Number
Problem Description
The program takes a number and reverses it.
Problem Solution
1. Take the value of the integer and store in a variable.
2. Using a while loop, get each digit of the number and store the reversed number in another variable.
3. Print the reverse of the number.
4. Exit.
Program/Source Code
Here is the source code of the Python Program to reverse a given number.
n=int(input("Enter number: "))
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
print("Reverse of the number:",rev)
Runtime Test Cases
Case 1:
Enter number: 124
Reverse of the number: 421
Case 2:
Enter number: 4538
Reverse of the number: 8354