def str2float(s):
s1 = s[:s.find('.')]
s2 = s[s.find('.')+1:]
reduce(lambda x, y: x*10 + y, map(int, s1))
reduce(lambda x, y: x/10 +y, map(int, s2[-1::-1]))
return reduce(lambda x, y: x*10 + y, map(int, s1)) + reduce(lambda x, y: x/10 +y, map(int, s2[-1::-1]))/10
str2float('123.456')
123.456
if abs(str2float('123.456') - 123.456) < 0.00001:
print('测试成功!')
else:
print('测试失败!')
测试成功!
Sign in to make a reply
叉烧叉烧
def str2float(s):
s1 = s[:s.find('.')]
s2 = s[s.find('.')+1:]
reduce(lambda x, y: x*10 + y, map(int, s1))
reduce(lambda x, y: x/10 +y, map(int, s2[-1::-1]))
return reduce(lambda x, y: x*10 + y, map(int, s1)) + reduce(lambda x, y: x/10 +y, map(int, s2[-1::-1]))/10
str2float('123.456')
123.456
if abs(str2float('123.456') - 123.456) < 0.00001:
print('测试成功!')
else:
print('测试失败!')
测试成功!