#!/usr/bin/env python
#coding:utf-8
import math
from functools import reduce
def is_palindrome(n):
a1 = str(n)
a = int(len(a1) / 2)
b1 = a1[:a]
b2 = a1[-a:]
b3 = b2[::-1]
if b3 == b1:
return 1
elif len(a1) ==1:
else :
return 0
output = filter(is_palindrome, range(1, 1000))
print('1~1000:', list(output))
if list(filter(is_palindrome, range(1, 200))) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191]:
print('测试成功!')
else:
print('测试失败!')
Sign in to make a reply
我不是中医
#!/usr/bin/env python
#coding:utf-8
import math
from functools import reduce
def is_palindrome(n):
a1 = str(n)
a = int(len(a1) / 2)
b1 = a1[:a]
b2 = a1[-a:]
b3 = b2[::-1]
if b3 == b1:
return 1
elif len(a1) ==1:
return 1
else :
return 0
output = filter(is_palindrome, range(1, 1000))
print('1~1000:', list(output))
if list(filter(is_palindrome, range(1, 200))) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191]:
print('测试成功!')
else:
print('测试失败!')