Python Program to Check if Given Number is Palindrome

Problem: Write a python program to check if given number is palindrome.

Solution: This program accepts a number from user. It reverses the given number and compares the original input number and reversed number, if both are same given number is palindrome else given number is not a palindrome.

Python program to check if given number is palindrom

num=int(input("Enter number:"))
original_number=num
reverse=0
while(num>0):
    digit=num%10
    reverse=reverse*10+digit
    num=num//10
if(original_number==reverse):
    print("Given number", original_number,"is a palindrome")
else:
    print("Given number", reverse,original_number,"is not a palindrome")

Note: // Operator is used to divide with integral result, remainder is discarded.

Output:

Enter number:121
Given number 121 is a palindrome