CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Write a function that checks whether an input number is a palindrome or not. [Note: A number or a string is called palindrome if it appears same when written in reverse order also. For example, 12321 is a palindrome while 123421 is not a palindrome]

Open in App
Solution

Program:
#program to find if the number is a palindrome
rev = 0
n = int(input("Enter the number: "))
#Storing the number input by user in a temp variable to run the loop
temp = n
#Using while function to reverse the number
while temp > 0:
digit = (temp % 10)
rev = (rev * 10) + digit
temp = temp // 10
#Checking if original number and reversed number are equal
if(n == rev):
print("The entered number is a palindrome.")
else:
print("The entered number is not a palindrome.")


OUTPUT:
Enter the Number: 114411
The entered number is a palindrome.

flag
Suggest Corrections
thumbs-up
2
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Introduction
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon