Palindrome Number Check

Check whether an integer is a palindrome using digit reversal.

PythonBeginner
Python
# Program to check palindrome number

num = int(input("Enter an integer: "))

temp = abs(num)
rev = 0

while temp > 0:
    digit = temp % 10
    rev = rev * 10 + digit
    temp //= 10

if num >= 0 and rev == num:
    print(num, "is a palindrome")
else:
    print(num, "is not a palindrome")

Output

Enter an integer: 121
121 is a palindrome

We reverse the digits and compare with the original number; for simplicity, we treat negative numbers as non-palindromes.