Python Program to Check if Given Number is Palindrome or Not using Recursion

Python Program to Check if Given Number is Palindrome or Not using Recursion

Write Python Program to Check if Given Number is Palindrome or Not using Recursion

# Write Python Program to Check if Given Number is Palindrome or Not using Recursion

def rev_number(n, result):
    
    if n == 0:
        return result
    
    result = (result * 10) + (n % 10)
    return rev_number(n // 10, result)
        
    
n = 52325
r = rev_number(n, 0)

if n == r:
    print(f'{n} is Palindrome')
else:
    print(f'{n} is Not Palindrome')

Output:

Run 1:
52325 is Palindrome

Run 2:
52321 is Not Palindrome