Learn about Program to Reverse Integer using Recursion Python in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Program to Reverse Integer using Recursion Python
# Python program to reverse a number using recursion reverse, base = 0, 1 #user-defined function def findReverse(num): global reverse global base if(num > 0): findReverse((int)(num/10)) reverse += (num % 10) * base base *= 10 return reverse # input from user num = int(input('Enter an integer number: ')) # print result print('The reverse number is =', findReverse(num))
Enter an integer number: 456
The reverse number is = 654
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Program to Reverse a Number in Python