Discuss / Python / 测试还行

测试还行

Topic source

nior_l

#1 Created at ... [Delete] [Delete and Lock User]

第一题:

def normalize(name):

    return name.capitalize()

第二题:

def prod(L):

    return reduce(lambda x,y:x*y,L)

第三题:

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

def str2float(s):

    point = s.find('.')

    def char2num(s):

        return DIGITS[s]

    def fn(x,y):

        return x*10+y

    num_1 = reduce(fn,map(char2num,s[:point]))

    num_2 = reduce(fn,map(char2num,s[point+1:]))

    return num_1 + num_2/pow(10,len(s[point+1:]))


  • 1

Reply