Palindrome Program in Python using Loop and Function

Oct 28, 2022

.

Admin

Palindrome Program in Python using Loop and Function

Hi Dev,

In this quick example, let's see Palindrome Program in Python using Loop and Function. This tutorial will give you simple example of Best String Palindrome Program in Python. I would like to share with you Palindrome Program in Python using while loop. we will help you to give example of Palindrome program in python using function Code Example. So, let's follow few step to create example of Palindrome number program.

Palindrome program in python; In this tutorial, you will learn how to create the palindrome program in python using function and while loop.

Following examples with output:

Example 1: 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: 1221

This 1221 number is palindrome!

Example 2: 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

I hope it can help you...

#Python