In the following example, we will check whether the given number (121) is a Palindrome number or not.
Example
Python Compiler
import math
num =121;
copyNum = num;
reverse =0;
#reverse a numberwhile(copyNum !=0):
reverse = reverse *10;
reverse = reverse + (copyNum %10);
copyNum = math.floor(copyNum /10);
if(num == reverse):
print("%d is a palindrome number"% num)
else:
print("%d is not a palindrome number"% num)
Output
121 is a palindrome number
Palindrome Numbers between the Given Range
In the following example, we will find all the Palindrome numbers between 10 and 50.
Example
Python Compiler
import math
start =10
end =50
flag =0print("Palindrome numbers between %d and %d: "% (start, end));
#reverse a numberfor start inrange(start, end):
copyNum = start;
reverse =0;
#reverse a numberwhile(copyNum !=0):
reverse = reverse *10;
reverse = reverse + (copyNum %10);
copyNum = math.floor(copyNum /10);
#resultif((start == reverse) and (start !=0)):
flag =1print(start, end=" ")
if(flag ==0):
print("There is no palindrome number between the given range")
Output
Palindrome numbers between 10 and 50:
11 22 33 44
Check Whether the Given Number is Palindrome or Not
In the following example, we will check whether the given number is a Palindrome Number or Not.
Example
Python Compiler
import math
num =int(input("Enter a (int) number: "));
copyNum = num;
reverse =0;
#reverse a numberwhile(copyNum !=0):
reverse = reverse *10;
reverse = reverse + (copyNum %10);
copyNum = math.floor(copyNum /10);
if(num == reverse):
print("%d is a palindrome number"% num)
else:
print("%d is not a palindrome number"% num)
Output
Enter a (int) number: 25
25 is not a palindrome number
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.
We are working to cover every Single Concept in Python.