1.回文数(60000,1000000)
def is_palindrome(n):
s=str(n)
return s[0:len(s)//2]==s[-1:len(s)//2:-1]
for i in filter(is_palindrome,range(60000,1000000)):
print(i)
return s[0:len(s)//2]==s[-1:len(s)//2:-1]
for i in filter(is_palindrome,range(60000,1000000)):
print(i)
运行结果
60006
60106
60206
60306
60406
.........
99599
99699
99799
99899
99999
60106
60206
60306
60406
.........
99599
99699
99799
99899
99999
2.判断回文数:
a = input('please input the number:')
b = str(a)
flag = True
for i in range(len(b)/2):
if b[i]!=b[len(b)-i-1]:
flag = False
break
if flag:
print "%d is huiwen number!" % a
else:
print "%d is not huiwen number!" % a
flag = True
for i in range(len(b)/2):
if b[i]!=b[len(b)-i-1]:
flag = False
break
if flag:
print "%d is huiwen number!" % a
else:
print "%d is not huiwen number!" % a
运行:
please input the number:124421
124421 is huiwen number!
124421 is huiwen number!