forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcentripetal_force.py
More file actions
37 lines (29 loc) · 858 Bytes
/
centripetal_force.py
File metadata and controls
37 lines (29 loc) · 858 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
30
31
32
33
34
35
36
37
"""
F = mv²/r
Where, F = Centripetal Force
m = Mass of the Body
v = Tangential Velocity
r = Radius of Circular Path
"""
def centripetal(mass: float, velocity: float, radius: float) -> float:
"""
The Centripetal Force formula is given as: (m*v*v)/r
>>> round(centripetal(15.5,-30,10),2)
1395.0
>>> round(centripetal(10,15,5),2)
450.0
>>> round(centripetal(20,-50,15),2)
3333.33
>>> round(centripetal(12.25,40,25),2)
784.0
>>> round(centripetal(50,100,50),2)
10000.0
"""
if mass < 0:
raise ValueError("The mass of the body cannot be negative")
if radius <= 0:
raise ValueError("The radius is always a positive non zero integer")
return (mass * (velocity) ** 2) / radius
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=True)