There was an error while loading. Please reload this page.
1 parent 6328322 commit 7e85caaCopy full SHA for 7e85caa
1 file changed
physics/newtons_second_law_of_motion.py
@@ -64,19 +64,22 @@
64
65
def newtons_second_law_of_motion(mass: float, acceleration: float) -> float:
66
"""
67
- Calculates force from `mass` and `acceleration`
+ Calculates force from `mass` and `acceleration`.
68
+ Raises ValueError if mass is negative.
69
70
>>> newtons_second_law_of_motion(10, 10)
71
100
72
>>> newtons_second_law_of_motion(2.0, 1)
73
2.0
74
+ >>> newtons_second_law_of_motion(-5.0, 10)
75
+ Traceback (most recent call last):
76
+ ...
77
+ ValueError: Mass cannot be negative
78
- force = 0.0
- try:
- force = mass * acceleration
- except Exception:
- return -0.0
79
- return force
+ if mass < 0:
80
+ raise ValueError("Mass cannot be negative")
81
+
82
+ return mass * acceleration
83
84
85
if __name__ == "__main__":
0 commit comments