Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions physics/newtons_second_law_of_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,22 @@

def newtons_second_law_of_motion(mass: float, acceleration: float) -> float:
"""
Calculates force from `mass` and `acceleration`
Calculates force from `mass` and `acceleration`.
Raises ValueError if mass is negative.

>>> newtons_second_law_of_motion(10, 10)
100
>>> newtons_second_law_of_motion(2.0, 1)
2.0
>>> newtons_second_law_of_motion(-5.0, 10)
Traceback (most recent call last):
...
ValueError: Mass cannot be negative
"""
force = 0.0
try:
force = mass * acceleration
except Exception:
return -0.0
return force
if mass < 0:
raise ValueError("Mass cannot be negative")

Check failure on line 81 in physics/newtons_second_law_of_motion.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W293)

physics/newtons_second_law_of_motion.py:81:1: W293 Blank line contains whitespace help: Remove whitespace from blank line
return mass * acceleration


if __name__ == "__main__":
Expand Down
Loading