Discuss / Python / 第二题

第二题

Topic source

罗修TM

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

只能针对这一种情况

from functools import reduce
def str2float(s):
    w=s[:3]+s[4:]
    def char2num(w):
        return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,'.':0}[w]
    def fn(x,y):
        return x*10+y
    def a(w):
        return reduce(fn, map(char2num, w))
    return a(w)*(0.001)
print('str2float(\'123.456\') =', str2float('123.456'))

罗修TM

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

错了,是第三题


  • 1

Reply