A number is known as a Palindrome number if the reverse of the number is same as the number. For example, 121 is a palindrome number, but 123 is is not a palindrome number.
In the below example, the number called MyNum is checked for palindrome number. The MyNum is first stored in a variable called Num. A while loop is used on this variable to perform following operations:
Finally, MyNum is compared with revNum to check whether the number is palindrome or not.
def Palindrome(MyNum): revNum = 0 Num = MyNum while(Num > 0): digit = Num % 10 revNum = revNum * 10 + digit Num = Num // 10 if MyNum == revNum: print(MyNum, "is a Palindrome number.") else: print(MyNum, "is not a Palindrome number.") Palindrome(12521) Palindrome(9779) Palindrome(1000)
12521 is a Palindrome number. 9779 is a Palindrome number. 1000 is not a Palindrome number.