First few palindrome numbers are 0, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99 , 101 , 111 , 121 , ... and so on.
前几个回文数为0、1、2、3、4、5、6、7、8、9、11、22、33、44、55、66、77、88、99、101、111、121,.... .. 等等。
Input format: Given a number n, size of list then next line contains space separated n numbers.
输入格式:给定数字n ,列表的大小 ,然后下一行包含空格分隔的n个数字。
Logic: We will simply convert the number into string and then using reversed(string) predefined function in python ,we will check whether the reversed string is same as the number or not.
逻辑:我们将简单地将数字转换为字符串,然后在python中使用反向(string)预定义函数,我们将检查反向字符串是否与数字相同。
Program:
程序:
# Give size of list
n=int(input())
# Give list of numbers having size n
l=list(map(int,input().strip().split(' ')))
print("Palindrome numbers are:")
# check through the list to check
# number is palindrome or not
for i in l:
num=str(i)
if("".join(reversed(num))==num):
print(i)
Output
输出量
翻译自: https://www.includehelp.com/python/print-palindrome-numbers-from-the-given-list.aspx