how to print palindrome in 100 between 250 in python
>>> def isPalindrome(s):
''' check if a number is a Palindrome '''
s = str(s)
return s == s[::-1]
>>> def generate_palindrome(minx,maxx):
''' return a list of Palindrome number in a given range '''
tmpList = []
for i in range(minx,maxx+1):
if isPalindrome(i):
tmpList.append(i)
return tmpList
>>> generate_palindrome(1,120)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111]
num=int(input("Enter a no.:"))
rev=0
num1=num
while num!=0:
rev=rev*10+(num%10)
num=num//10
if num1==rev:
print(num1," is a palindrome")
else:
print(num1," is not a palindrome")
n = input("Enter the word and see if it is palindrome: ") #check palindrome
if n == n[::-1]:
print("This word is palindrome")
else:
print("This word is not palindrome")
print("franco")
myString = "aba"
if myString == myString[::-1]:
print("The string '" + myString + "' is a palindrome")
else:
print("The string '" + myString + "' is not a palindrome")
string = input("Type a string: ")
if string[::-1] == string:
print(string,"This string is Palindrome")
else:
print(string,"This string is not Palindrome")
# Python3 code to demonstrate
# checking a number is palindrome
# using str() + string slicing
# initializing number
test_number = 9669669
# printing the original number
print ("The original number is : " + str(test_number))
# using str() + string slicing
# for checking a number is palindrome
res = str(test_number) == str(test_number)[::-1]
# printing result
print ("Is the number palindrome ? : " + str(res))
# Python3 code to demonstrate
# checking a number is palindrome
# using math.log() + recursion + list comprehension
import math
# the recursive function to reverse
def rev(num):
return int(num != 0) and ((num % 10) *
(10**int(math.log(num, 10))) +
rev(num // 10))
# initializing number
test_number = 9669669
# printing the original number
print ("The original number is : " + str(test_number))
# using math.log() + recursion + list comprehension
# for checking a number is palindrome
res = test_number == rev(test_number)
# printing result
print ("Is the number palindrome ? : " + str(res))