Discuss / Python / 答题

答题

Topic source

大熊Cody

#1 Created at ... [Delete] [Delete and Lock User]
def char2num(s):
    return {
        '0':0,
        '1':1,
        '2':2,
        '3':3,
        '4':4,
        '5':5,
        '6':6,
        '7':7,
        '8':8,
        '9':9,
    }[s]

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

L1 = ['adam','LISA','barT']
L2 = list(map(normalize,L1))
print(L2)

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

print('3 * 5 * 7 * 9 =' , prod([3,5,7,9]))

def str2float(s):
    l = s.split('.')
    def fn(x,y):
        return x * 10 + y
    return reduce(fn,map(char2num,l[0])) + reduce(fn,map(char2num,l[1])) / pow(10,len(l[1]))

print(str2float('123.345'))

  • 1

Reply