;

Python Program to Reverse a Number using Recursion


Tutorialsrack 26/04/2020 Python

In this Python program, we will learn how to reverse a number using recursion.

Here is the source code of the program to reverse a number using recursion.

Python Program to Reverse a Number using Recursion
# Python Program to Reverse a Number using Recursion

Reverse = 0

# Defining a Recursive Function
def Reverse_Integer(Number):
    global Reverse
    if(Number > 0):
        Reminder = Number %10
        Reverse = (Reverse *10) + Reminder
        Reverse_Integer(Number //10)
    return Reverse

# Take the Input From the User
Number = int(input("Enter any Number: "))
Reverse = Reverse_Integer(Number)
print("Reverse of entered number is = %d" %Reverse)
Output

Enter any Number: 523654

Reverse of entered number is = 456325

 

Enter any Number: 52456

Reverse of entered number is = 65425


Related Posts



Comments

Recent Posts
Tags