Discuss / Python / 小白验证通过,感觉好麻烦

小白验证通过,感觉好麻烦

Topic source

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

def str2float(s): def create_char(s): a = s.index('.') return s[:a], s[a + 1:] x, y = create_char(s)

def char2num(s):
    return DIGITS[s]

def fn1(j, k):
    return j*10+k

a = reduce(fn1, map(char2num, x))
b = reduce(fn1, map(char2num, y))

def divide(lengh, c):
    while lengh>0:
        c=c/10
        lengh = lengh-1
    return c
c = divide(len(str(b)), b)

return a+c

  • 1

Reply