Description: Palindrome
A palindromic number (also known as a digit palindrome or numeric palindrome) is a number that remains the same when its digits are reversed. For example, 16461, is “symmetric”.
What is palindrome number example?
The term palindromic is derived from the palindrome, which refers to a word (such as a rotor or racecar) whose spelling is unchanged when its letters are reversed. The first 30 palindromic numbers (in decimal) are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, etc. …..
Sentence-length palindromes can be written when allowances are made for the adjustment of capital letters, punctuation marks, and word dividers, such as “one man, one plan, one canal, Panama!”
How to Check the given number is palindrome or not?
In this program, we will learn to check the given number is palindrome or not. If it is palindrome then print palindrome and if not then print not a palindrome.
Algorithm:
- Step 1: Start
- Step2: Declare the variable n and read n.
- Step3: Assign k to n
- Step 4: Initialize r to 0
- Step 5: in the while loop
- Display
- d = n% 10
- R = r * 10 + d
- N = math.floor (n / 10)
- Step 6: Check the status r == k.
- Step 7: If the condition is correct that the given number is a palindrome
- Step 8: Otherwise print that the given number is not Palindrome
- Step 9: End
Source Code: Number is Palindrome or Not
number = int(input("Enter a number:"))
temp = number
reverse = 0
while (number > 0):
digits = number % 10
reverse = reverse * 10 + digits
number = number // 10
if (temp == reverse):
print("The given number is palindrome!")
else:
print("The given number is Not a palindrome!")
Output:
Enter a number:212
The given number is palindrome!
>>
Enter a number: 52
The given number is Not a palindrome!
Recommended Posts:
- How to Become a Machine Learning Engineers – easy Step by Step Guide
- Python Difference Between Two Lists using Python Set and Without Set
- How to Open file in python|Read File Line by Line with Examples
- Python String Find() Method Explained with Examples
- How to Generate Random Numbers in Python with Examples
Get Salesforce Answers