This blog post discusses how to check if an input number is a palindromic number. A palindrome is a number that remains the same when its digits are reversed. For instance, 15651 is a palindrome, but 223 is not a palindrome.
Except for 0, a palindromic number’s leftmost digit must be non-zero.
n = int(input("Enter an input number to check if it is a palindrome: "))
temp_value = n
reverse = 0
while(n > 0):
digit = n % 10 #using 'Modulus' 10 to find the last digit
reverse = reverse * 10 + digit #stores this digit in 'reverse'
n = n // 10 #removes this digit from the number by using 'integer division'
print("The reverse of your input number is: ", reverse)
if(temp_value == reverse): #tests if the original number and the reverse of the number are equal
print("Yay :) The input number is a palindrome!")
else:
print("Unfortunately, your input number: ", temp_value, " is not a palindrome!")
Feel free to try the code below, by inputting a few numbers: