作业第三题 小数点那里查阅了一下别人的博客 但是还是不是很明白为什么会出错 求讲解
Topic source但是我试了一下没有问题啊
from functools import reducedef str2float(s): n=s.index('.') L1 = reduce(lambda x,y:x*10+y, map(int, s.replace('.', ''))) return L1 / (10 ** n)print('str2float(\'123.456\') =', str2float('123.456'))if abs(str2float('123.456') - 123.456) < 0.00001: print('测试成功!')else: print('测试失败!')
- 1
Fwmmmm-