Discuss / Python / 作业

作业

Topic source

南小i

#1 Created at ... [Delete] [Delete and Lock User]
def is_palindrome(n):
    s = str(n)
    count = 0
    if len(s) > 1:
        for n in range(int(len(s) / 2)):
            if s[n] != s[-1 - n]:
                count = count + 1
        return not count
    else:
        return True

判断语句里有filter,就不用自己写生成器了

南小i

#2 Created at ... [Delete] [Delete and Lock User]
def is_palindrome(n):
    s = str(n)
    return s[::] == s[::-1]

切片

南小i

#3 Created at ... [Delete] [Delete and Lock User]
def is_palindrome(n):
    s = str(n)
    count = 0
    for n in range(int(len(s) / 2)):
        if s[n] != s[-1 - n]:
            count = count + 1
    return not count

发现并不需要判断一位数


  • 1

Reply