Discuss / Python / 求帮助呀~小白一个

求帮助呀~小白一个

Topic source

from functools import reduce def str2float(s): a,b=s.split('.') def K(x,y): return x*10+y def cha2num(s): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s] A=reduce(K,map(a,cha2num(a))) B=reduce(K,map(b,cha2num(b))) return A+B/len(B) print('str2float(\'123.456\') =', str2float('123.456'))

想知道我的代码哪里有问题额。。。。

aaronchou0

#2 Created at ... [Delete] [Delete and Lock User]
return A+B/10**len(B)

不是除以B的长度 而是除以B的长度位数0.234是要除以1000的


  • 1

Reply