We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 46f8bb0 commit 183acdaCopy full SHA for 183acda
samples/functional/do_reduce.py
@@ -40,17 +40,17 @@ def str2int(s):
40
41
def str2float(s):
42
nums = map(lambda ch: CHAR_TO_FLOAT[ch], s)
43
- point = -1
+ point = 0
44
def to_float(f, n):
45
nonlocal point
46
if n == -1:
47
- point = 0
+ point = 1
48
return f
49
- if point == -1:
+ if point == 0:
50
return f * 10 + n
51
else:
52
- point = point + 1
53
- return f + n / pow(10, point)
+ point = point * 10
+ return f + n / point
54
return reduce(to_float, nums, 0.0)
55
56
print(str2float('0'))
0 commit comments