Python Program to Check Palindrome Number using While loop
ADVERTISEMENTS
Python program to check palindrome number using while loop. In this article, you will learn how to make a python program to check palindrome number using while loop.
What is Palindrome Number?
A palindrome is a case where if the reverse of any number will be matched correctly with its original integer number, It will be a palindrome.
Palindrome Number Formula
7997 == 7997 => a palindrome
Source Code
# Python Program to Check Palindrome Number using While loop
print ("Enter an integer number::\n")
x, r, rN, oN = int(input()), 0, 0, 0
# rN - To store the reverse number
# oN - To store the original number
# r - To store the remainder
oN = x
# this reverse number will be stored during iteration
while x!= 0:
r = x % 10
r = r if r >= 1 else 0
rN = rN * 10 + r
rN = round (rN) if rN else 0
x /= 10
x = x if x >= 1 else 0
rN = round (rN) if rN else 0
# if the original number will match with reverse
# then the palindrome case will be true
if oN == rN:
print ("This ", oN, " is a palindrome number.")
else:
print ("This ", oN, " is not a palindrome number!")
Output
Enter an integer number::
90009
This 90009 is a palindrome number.