Palindrome Check Program in Python

Palindrome Check Program in Python | ninjasquad

In our previous Python tutorial, you have learned to create Fibonacci Series in Python. In this tutorial, we will explain how to write a Python program to check whether a number or string is Palindrome.

A palindrome is a number or letter that remains the same even if the number and string are reversed.

For example, if we reverse below numbers, it will remain same.


below strings will also remain same after reversed.


So all these numbers and strings are palindrome.

Palindrome Number Check Program Python

Here we will implement with while loop to check if number is Palindrome or not.

number = int(input("\nEnter number:"))
originalNumber = number

reverse = 0
while(number > 0):
    digit = number % 10
    reverse = reverse * 10 + digit
    number = number // 10
if(originalNumber == reverse):
    print("\nThe number is palindorme!")
    print("\n The number isn't a palindorme!")

Palindrome String Check Program Python

Here we will check whether user inputted string is Palindrome.

string = input("\nEnter string:")

string = string.casefold()

reversedString = reversed(string)

if list(string) == list(reversedString):
   print("The string is a palindrome.")
   print("The string is not a palindrome.")

Source: Internet

Leave a Comment

We are offering free coding tuts