# Python program for palindrome

Written by

Himani Kohli

## Program to check palindrome number in python

In this program, we are going to check whether the given number is palindrome or not by using python.

Before we start our program, there is a need to know what is a palindrome?

The palindrome is set to be a number whose reverse is said to be equal. In this program, we will be using if and while statement. If the given condition placed in “if ” statement is true then it is a palindrome else it is not.

For Example:

Input: 121
Output: It is a palindrome

Algorithm:

1. Take a number from the user and store in a variable.
2. Transfer the value of number to the temporary variable.
3. With the help of while loop we reverse the number and store it in the variable.
4. We will check the reverse number with the temporary variable.
5. If both are equal then it is a palindrome.
6. Else it is not a palindrome.

Code:

``````#program to check given number is palindrome or not
``````n= int(input(“Enter the number: ”))
temp=n //storing the number in temporary variable
rev=0
while(n>0):
digit=n%10
rev=rev*10+digit //reversing the digit and storing it in a variable
n=n//10
if (temp==rev) : //comparing temp variable and rev variable
print(“It is a palindrome ”)
else:
print(“It is not a palindrome ”)``````

Output:

``````Enter the number: 191
It is a palindrome``````