write a program to reverse an integer value 54321 python

Here is a sample Python program that reverses an integer value:

# Function to reverse an integer
def reverse(num):
  # Reverse the number
  reverse = 0
  while num > 0:
    reverse = (reverse * 10) + (num % 10)
    num = num // 10

  return reverse

# Test the function
print(reverse(54321))

This program defines a function reverse() that takes an integer num as input and returns the reversed version of the number. The function uses a while loop to reverse the digits of the number one by one, and then returns the reversed number.

The function is then tested by calling it with the input 54321. The output should be 12345, which is the reversed version of the input number.

Leave a Comment