Discuss / Python / day8 打卡 今天独立完成三道题,开心

day8 打卡 今天独立完成三道题,开心

Topic source

第一题答案:

def normalize(name):
    return name.capitalize()

第二题答案:

def prod(L):
    def multiply(x,y):
        return x*y
    return reduce(multiply,L)

第三题答案:

    i=s.index('.')
    s_int=s[0:i]
    s_float=s[i+1:]
    def fn(x, y):
        return x * 10 + y
    def char2num(s):
        DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
        return DIGITS[s]
    return reduce(fn, map(char2num, s_int))+reduce(fn, map(char2num,s_float))/(10**len(s_float))

capitalize是个啥


  • 1

Reply