Python Program to Reverse a number in given n Digit Number using while Loop
In this example shows, how to reverse a digits number in given n digit number using whileloop.
Steps
- Get the input from user.
- Use modulo to extract the digits from the number.
- Divide to shorten the number after the digit has been extracted.
Example:
Example.py
a = int(input("Enter the Value :"))
rev = 0
while(a != 0):
count = a % 10
rev = rev * 10 + count
a = a//10
print("Reversed Number is : " + str(rev))
Example.py
a = int(input("Enter the Value :")) rev = 0 while(a != 0): count = a % 10 rev = rev * 10 + count a = a//10 print("Reversed Number is : " + str(rev))
Output
Enter the Value :123456 Reversed Number is : 654321