Code of the Python Program to reverse a given number

Configurare noua (How To)

Situatie

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.

Backup

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)

Solutie

Runtime Test Cases
 
Case 1:
Enter number: 124
Reverse of the number: 421
 
Case 2:
Enter number: 4538
Reverse of the number: 8354

Tip solutie

Permanent

Voteaza

(2 din 5 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?