Program to check if a number is palindrome in python
In this python programming guide, we are going to write a
-
python program to check if a number is palindrome
Python program to check if a number is palindrome
The program to check if a number is palindrome in python is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
num = int(input("Enter a number: "))
temp = num
reverse=0
while num > 0:
last_dig = num % 10
reverse = reverse * 10 + last_dig
num = num // 10
if temp == reverse:
print("The number is palindrome!")
else:
print("The number is not a palindrome!")
The output of python program to check if a number is palindrome or not is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a number: 1221
The number is palindrome!
Few important tips about this program
1. A palindrome number is such a number which when reversed, remains the same.
2. In this program, we took out the last digit of every number, create a new number in the reverse order and reduce the old number.
3. If the newly formed number is same as the older one, then it is a Palindrome number else it is not.
Python program to check if a number is palindrome or not snapshot is given below:
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :
Published Date :
Dec 30,2021