-
-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Expand file tree
/
Copy pathcentripetal_force.py
More file actions
29 lines (25 loc) · 894 Bytes
/
centripetal_force.py
File metadata and controls
29 lines (25 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def centripetal_force(mass: float, velocity: float, radius: float) -> float:
"""
Calculate the centripetal force acting on an object in circular motion.
Formula:
F = (m * v^2) / r
Reference:
https://byjus.com/physics/centripetal-and-centrifugal-force/
>>> centripetal_force(2, 4, 2)
16.0
>>> centripetal_force(1, 3, 1)
9.0
>>> centripetal_force(-1, 3, 2)
Traceback (most recent call last):
...
ValueError: The mass of the body cannot be negative
>>> centripetal_force(2, 3, 0)
Traceback (most recent call last):
...
ValueError: The radius must be a positive non-zero number
"""
if mass < 0:
raise ValueError("The mass of the body cannot be negative")
if radius <= 0:
raise ValueError("The radius must be a positive non-zero number")
return (mass * velocity**2) / radius