Discuss / Python / 作业3

作业3

Topic source

默_kk

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

小数部分的计算 倒排序部分借鉴了别人的。

在此插入代码

from functools import reduce

d = {} for i in range(10): d[str(i)] = i

print(d)

def str2int(s): return d[s] def str2float(s): m = s.index('.') t1 = reduce(lambda x, y: 10 * x + y, map(str2int, s[:m])) t2 = reduce(lambda x ,y: x /10 + y, list(map(str2int, s[m+1:]))[::-1])/10 return t1 + t2

print(str2float('98765.56789'))


  • 1

Reply