(Print the digits in an integer reversely) Write a recursive function that displays an integer value reversely on the console using the following header:
def reverseDisplay(value):
For example, invoking reverseDisplay(12345) displays 54321. Write a test program that prompts the user to enter an integer and displays its reversal.
Print the digits in an integer reversely Program code:
#Recursive function to display an integer value reversely.
def reverseDisplay(value):
# Base case: If the value is 0, we have printed all the digits.
if value == 0:
return
# Recursive case: Print the last digit of the value
#and recursively call reverseDisplay with the remaining
#digits (excluding the last digit).
last_digit = value % 10
print(last_digit, end="")
reverseDisplay(value // 10)
# Prompt and read the the user for input
value = int(input("Enter an integer number: "))
# Display the reversal of the input value
print("Reverse order:", end=" ")
reverseDisplay(value)
print()
Executed Output:
Enter an integer number: 12345
Reverse order: 54321