Advertisements
Advertisements
प्रश्न
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 the same when written in reverse order also. For example, 12321 is a palindrome while 123421 is not a palindrome.]
संक्षेप में उत्तर
Advertisements
उत्तर
Program:
#program to find if the number is a palindrome
rev = 0
n = int(input("Enter the number: "))
#Storing the number input by the user in a temp variable to run the loop
temp = n
#Using the while function to reverse the number
while temp > 0:
digit = (temp % 10)
rev = (rev * 10) + digit
temp = temp // 10
#Checking if the 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.shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
