Palindrome Number in Python Using While Loop

Palindrome Number in Python Using While Loop for beginners. Madam, I’m Adam is an example of a palindrome, which is a word, phrase, or sentence that reads the same backwards and forwards. Palindromes in reverse, or semordnilaps, are words that spell other words when spelled backwards, such as star/rats and drawer/reward.

Temp Variable in Python

Tempfile is a Python module that allows us to read multiple files, change or access the data in the files, and generate output files based on the processed data. After the program was completed, each of the output files generated during its execution was no longer required. Temp (or temporary) is a variable that is used to store temporary data (numbers, characters, etc.) that may be used later in the program execution.

rev Function to Execute Palindrome Number in Python

The reversed() method in Python returns an iterator that accesses the given sequence backwards. Python’s built-in reverse() and reversed() methods are used. Without creating a new list, these methods will reverse the list. The elements in the original list object will be reversed using Python’s reverse() and reversed() functions.

While Loop in Python

Python While Loop is a programming construct that is used to repeatedly execute a set of statements until a condition is met. When the condition in the program becomes false, the line immediately after the loop is executed. While loop is classified as an indefinite iteration.

num=int(input("Enter The Number"))
temp=num
rev=0
while(num>0):
    dig=num%10
    rev=rev*10+dig
    num=num//10
if(temp==rev):
    print("The {0} number is palindrome".format(temp))
else:
    print("Not a palindrome")

Output:

Enter number 45654
The number is a palindrome