from functools import reduce
def f1(x, y):
return x * 10 + y
def str2float(s):
n = 0
while n < len(s):
if s[n]== '.':
break
else:
n = n + 1
L1 = reduce(f1, list(map(int, s[:n])))
return L1 + int(s[n+1:])*0.1**(len(s)-n-1)
Sign in to make a reply
Coal and gas outburst 💨
from functools import reduce
def f1(x, y):
return x * 10 + y
def str2float(s):
n = 0
while n < len(s):
if s[n]== '.':
break
else:
n = n + 1
L1 = reduce(f1, list(map(int, s[:n])))
return L1 + int(s[n+1:])*0.1**(len(s)-n-1)