Python Program to Check a Palindrome Number or Not

Python Program to check palindrome number

Hey Shouters !! Today we have come up with the Python Program to check a palindrome number.

If you are a complete beginner and do not how to write a code in python, please check Introduction to Python.

What is a palindrome?​

A string or a number is said to be palindrome if the reverse of the string is the same as string. For example, “radar” is a palindrome, but “radix” is not a palindrome.​

Python Program to Check if a Number is a Palindrome​-

This is a Python Program to check whether a given number is a palindrome or not.​

Problem Description​
The program takes a number and checks whether it is a palindrome or not.​

Problem Solution​
1. Take the value of the integer and store it in a variable.​
2. Transfer the value of the integer into another temporary variable.​
3. Using a while loop, get each digit of the number and store the reversed number in another variable.​
4. Check if the reverse of the number is equal to the one in the temporary variable.​
5. Print the final result.​
6. Exit.​

Program/Source Code​-

Here is the source code of the Python Program to check whether a given number is a palindrome. The program output is also shown below.​

How the Code Works?

1. Users must first enter the value of the integer and store it in a variable.​
2. The value of the integer is then stored in another temporary variable.​
3. The while loop is used and the last digit of the number is obtained by using the modulus operator.​
4. The last digit is then stored at the one’s place, second last at the ten’s place, and so on.​
5. The last digit is then removed by truly dividing the number with 10.​
6. This loop terminates when the value of the number is 0.​
7. The reverse of the number is then compared with the integer value stored in the temporary variable.​
8. If both are equal, the number is a palindrome.​
9. If both aren’t equal, the number isn’t a palindrome.​
10. The final result is then printed.​

Runtime Test Cases​-

Case 1​
Enter number:121​
The number is a palindrome!​

Case 2​
Enter number:567​
The number isn’t a palindrome!​

If you are currently preparing for IT companies and want to give the best shot.

On Instagram, we daily add Multiple Choice Questions related to all the programming language, Follow Us Now

Recommended Posts-

  1. Introduction to Python
  2. Python Program to check a leap year
  3. Word Guessing Game in Python
  4. Free Python Course of Udemy

5 thoughts on “Python Program to Check a Palindrome Number or Not

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner