Python Program To Reverse the Given Number | RRTutors
Published January 07, 2021In this program we will write a python program to revese the given number.
We can reverse a number in python by belwo ways
- Using for-loop
- Using while-loop
Using for-loop
x=(input("Enter a Number: x= ")) |
Using while-loop
n=int(input("Enter number: ")) |
Output:
Enter number: 126758 |
- Take input from user and store it in a variable n.
- By using the while loop we obtained last character by using modulus operator
- The last digit will stored at one’s place, next second is at the ten’s place and so on.
- The last digit is then removed by truly dividing the number with 10.
- Then While loop will return when the value of the number is 0.
- Finally revere of the given number will return
Article Contributed By :
|
|
|
|
1859 Views |