Discuss / Python / 打卡交作业,膜拜各位大佬

打卡交作业,膜拜各位大佬

Topic source

第一题:

def normalize(name):

    result = name[0].upper() + name[1:].lower()

    return result

第二题:

def prod(L):

    def multiply(x, y):

        return x * y

    return reduce(multiply, L)

第三题:

    def integer(x, y):

        return x * 10 + y

    def point(x, y):

        return x / 10 + y

    DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

    def char2num(s):

        return DIGITS[s]

    loc = s.find('.')

    s1 = s[:loc]

    s2 = s[loc + 1:]

    s2 = s2[::-1]

    int = reduce(integer, map(char2num, s1))

    float = reduce(point, map(char2num, s2))

    return int + float /10


  • 1

Reply