Skip to content

Commit faa4139

Browse files
author
Zo Bot
committed
remove dead try/except wrapper around mass * acceleration in newtons_second_law_of_motion — the function signature is annotated (mass: float, acceleration: float) -> float, and multiplying two float values cannot raise any exception on valid inputs. The previous 'try: force = mass * acceleration; except Exception: return -0.0' wrapper was dead code that silently masked TypeError when a caller violated the type contract (e.g. passing a string), KeyboardInterrupt, SystemExit, and any unrelated bug in this function body, by returning the unusual signed zero -0.0 which can poison downstream numerical code (-0.0 == 0.0 in equality checks but is distinct in repr and bit pattern). The plain expression makes the implementation match its type signature and its existing doctests; the two doctests still pass (100 and 2.0)
1 parent 234e0e7 commit faa4139

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

physics/newtons_second_law_of_motion.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ def newtons_second_law_of_motion(mass: float, acceleration: float) -> float:
7171
>>> newtons_second_law_of_motion(2.0, 1)
7272
2.0
7373
"""
74-
force = 0.0
75-
try:
76-
force = mass * acceleration
77-
except Exception:
78-
return -0.0
79-
return force
74+
return mass * acceleration
8075

8176

8277
if __name__ == "__main__":

0 commit comments

Comments
 (0)