Python program to Check palindrome Number | iterative method

Posted by

In this Post you will learn how to write a program in Python to check a given number is palindrome or not using iterative method.

Before moving directly on the writing the program to check whether a given number is palindrome or not, you should know

What is Palindrome Number?

A Palindrome number is a number which reverse is equal to the original number means number itself.

For example : 121, 111, 1223221, etc.

In the above example you can see that 121 is a palindrome number. Because reverse of the 121 is same as 121.

How our program will behave?

Suppose if someone gives an input 121 then our program should print “Number is a palindrome”.

And if someone given input 123 the our program should print “Number is not a palindrome number”.

Python program to Check palindrome number using iterative method

n = int(input("please give a number : "))
reverse,temp = 0,n
while temp!=0:
    reverse = reverse*10 + temp%10;        
    temp=temp//10;
if reverse==n:
    print("Number is a palindrome")
else:
    print("Number is not a palindrome number")

Leave a Reply

Your email address will not be published. Required fields are marked *