Python program to check whether number is palindrome or not

Python program to check whether number is palindrome or not:

Basic: If a number remains same, even if we reverse its digits then the number is known as palindrome number. For example 121 is a palindrome number because it remains same if we reverse its digits.

Program Description:

This program ask user to enter any number and check whether the given number is a Palindrome number or not.

Below is the ways to check whether the given number is Palindrome number or not :

Program Logic:

  • Give the number as user input using the int(input()) function and store it in a n variable.
  • Take a variable say rev and initialize its value to 0.
  • Assign the given number to ori variable.
  • Using a while loop, get each digit of the number and store the reversed number in another variable
  • Check if the reverse of the number is equal to the one in the temporary variable.
  • Print the final result.
  • Exit.

Below is implementation code:

Here is source code of the Python Program to check whether a given number is a palindrome.

n = int(input("Enter any Number: "))
rev = 0
ori = n
while(n > 0):
    d = n % 10
    rev = (rev * 10) + d
    n = n //10
print("Reverse of a given number is =%d" %rev)
if(ori == rev):
    print("%d is a Palindrome Number" %ori)
else:
    print("%d is not a Palindrome Number" %ori)

Output:

Enter any Number: 121

Reverse of a given number is =121

121 is a Palindrome Number

Output:

>>> %Run palindrome.py

Enter any Number: 123

Reverse of a given number is =321

123 is not a Palindrome Number

Below is snapshot of executable code with output

python program to check whether number is plaindrome or not

You can check this too

  1. Program to write user defined function to swap two number and display number before swapping and after swapping
  2. Python Program to calculate arithmetic operation on two number using user defined function
  3. Program to print multiplication table of any number

<