Python Palindrome Program

Python palindrome program; Through this tutorial, i am going to show you how to write palindrome program in python using while loop and function.

Python Palindrome Programs

  • Python Palindrome Program using While Loop
  • Palindrome Program in Python using function

Python Palindrome Program using While Loop

num=int(input("Enter any number:"))
temp=num
rev=0
while(num>0):
    dig=num%10
    rev=rev*10+dig
    num=num//10
if(temp==rev):
    print("The {0} number is palindrome!".format(temp))
else:
    print("Not a palindrome!")

Output

Enter any number: 121
This 121 number is palindrome!

Palindrome Program in Python using Function

# Python Palindrome Program using Functions
 
reverse = 0
def integer_reverse(number):
    global reverse
    
    if(number > 0):
        Reminder = number % 10
        reverse = (reverse * 10) + Reminder
        integer_reverse(number // 10)
    return reverse
number = int(input("Enter any Number: "))
rev = integer_reverse(number)
if(number == rev):
    print("The %d is a Palindrome Number" %number)
else:
    print("The %d is not a Palindrome Number" %number)

Output

Please Enter any Number:  151
The 151 is a Palindrome Number

Recommended Python Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *