Discuss / Python / 交作业

交作业

Topic source

与非----

#1 Created at ... [Delete] [Delete and Lock User]
def is_palindrome(n):
    n = str(n)
    y = ""
    if len(n) == 1:  #排除个位数
        return 0
    a = len(n) -1    #获取n的最后一个下标
    while a >= 0:    #通过下标反向读取
        x = n[a]
        y = y+x
        a = a-1
    return y == n
output = filter(is_palindrome, range(1, 10000))
print(list(output))

  • 1

Reply