Palindrome Number Checker using Python
Topic: Palindrome Number Checker using Python.
Hey Guys, today we are going see a Python Program to check whether a number is Palindrome or not.
Title: Python Code for Palindrome Number Checker with user input. (Beginner Friendly + Easy + Code + Output + Online Compiler)
What is this program and why we are going to use it?
This Program consists of Variables, Input Function, Loop (while loop), Condition (if-else) and Arithmetic Operators.
By using variables, we are going to store values in variables in int format. By using input function, we are going to input values from the user. For example:
n = 121
Here n is a variable where 121 is assigned to n.
A palindrome number is a number that remains the same when reversed.
By using variables, we are going to store values in variables in int format. By using input function, we are going to input values from the user. For example:
n = 121
Here n is a variable where 121 is assigned to n.
A palindrome number is a number that remains the same when reversed.
n = int(input("Enter a number: "))
So, this will ask user to input a number.
Logic:
1. Take a number (n) from user.
2. Store original number in temp.
3. Initialize reverse = 0.
4. Use a while loop until n > 0.
- Extract last digit using digit = n % 10
- Add digit to reverse using reverse = reverse * 10 + digit
- Remove last digit using n = n // 10
5. Compare reverse with original number.
6. If equal → Palindrome, else → Not Palindrome.
Code:
Online Compiler (Switch to Interactive Mode before execution):
Example Output:
Input: 121
Output: Palindrome
Input: 123
Output: Not Palindrome
Output: Palindrome
Input: 123
Output: Not Palindrome
Applications:
1. Used in number-based problem solving
2. Helps in understanding loops and conditions
3. Used in algorithm and logic building concepts
2. Helps in understanding loops and conditions
3. Used in algorithm and logic building concepts
Comments
Post a Comment