In this Python Program, we are given a number a number and we have to output its reverse.

Steps to Reverse a Number

  1. Take a number as input.
  2. Run while loop with condition number > 0.
  3. Add the last digit of the number to the reverse i.e reverse = reverse*10 + number%10.
  4. Remove the last digit from number i.e number = number/10.

Reverse a Number in Python

#Reverse Number in Python

print("Enter a Number \n")
num = int(input())
rev = 0
while num > 0:
    rev = (rev*10) + (num %10);
    num = num//10
print("Reverse is: %d " %rev)



Reverse a number in Python

That’s all we need to write in python to reverse a number. If you have any Doubts then comment below.

Leave a Reply

1 × 1 =