Python Program to Reverse a Given Number

In this program we reverse a given number using python programming language.

Reversing a given number requires integer division. and here we use operator // for integer division.

Please check following two cases for division:

Case 1: Floating Point Division ( / ) Operator

>>> 7/3
2.3333333333333335

Case 2: Integer Division ( // ) Operator

>>> 7//3
2

Python Program to Reverse a Given Number


# Python Program to Reverse Given Number

# Reading Number and Converting to Integer
number = int(input('Enter Number: '))
copy = number

# Set Reverse variable to 0
reverse = 0

# Finding Reverse
while number != 0:
    remainder = number%10
    reverse = reverse *10 + remainder
    number = number//10

# Displaying Reverse
print('Reverse of %d is %d' %(copy, reverse))

Output

Enter Number: 123456
Reverse of 123456 is 654321