Discuss / Python / 题3,考虑了输入整数的情况

题3,考虑了输入整数的情况

Topic source

Vency_熙爷

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

from functools import reduce

def char2num(m): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[m]

def str2float(a): n = 0 p = list(a) while n < len(p): if p[n] == '.': p.pop(n) break else: n = n + 1

m, b = 0, 1
if n == len(p):
    b = 1
else:
    while m < n:
        b = b * 0.1
        m = m + 1

def fn(x, y):
    return 10 * x + y
p = map(char2num, p)
return reduce(fn, p) * b

  • 1

Reply