GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — update str2float · WangLeGeWang/learn-python3@183acda

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • samples/functional
    • do_reduce.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎samples/functional/do_reduce.py‎

Copy file name to clipboardExpand all lines: samples/functional/do_reduce.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ def str2int(s):
4040

4141
def str2float(s):
4242
nums = map(lambda ch: CHAR_TO_FLOAT[ch], s)
43-
point = -1
43+
point = 0
4444
def to_float(f, n):
4545
nonlocal point
4646
if n == -1:
47-
point = 0
47+
point = 1
4848
return f
49-
if point == -1:
49+
if point == 0:
5050
return f * 10 + n
5151
else:
52-
point = point + 1
53-
return f + n / pow(10, point)
52+
point = point * 10
53+
return f + n / point
5454
return reduce(to_float, nums, 0.0)
5555

5656
print(str2float('0'))

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.