Reverse a Number in Python Using For Loop

(Last Updated On: 28/12/2022)

Python Program to Reverse a Number Using For Loop

# Reverse a Number in Python Using For Loop

# we are taking a number from user as input
num = input("Enter the first number:")

# calculate reverse of number
reverse = ''
for i in range(len(num), 0, -1):
   reverse += num[i-1]

# print reverse of number
print('The reverse number is =', reverse)

Output:

Enter the first number:12356
The reverse number is = 65321

Leave a Reply

Your email address will not be published. Required fields are marked *