MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / terminal_velocity

Function terminal_velocity

physics/terminal_velocity.py:27–54  ·  view source on GitHub ↗

>>> terminal_velocity(1, 25, 0.6, 0.77) 1.3031197996044768 >>> terminal_velocity(2, 100, 0.45, 0.23) 1.9467947148674276 >>> terminal_velocity(5, 50, 0.2, 0.5) 4.428690551393267 >>> terminal_velocity(-5, 50, -0.2, -2) Traceback (most recent call last): ...

(
    mass: float, density: float, area: float, drag_coefficient: float
)

Source from the content-addressed store, hash-verified

25
26
27def terminal_velocity(
28 mass: float, density: float, area: float, drag_coefficient: float
29) -> float:
30 """
31 >>> terminal_velocity(1, 25, 0.6, 0.77)
32 1.3031197996044768
33 >>> terminal_velocity(2, 100, 0.45, 0.23)
34 1.9467947148674276
35 >>> terminal_velocity(5, 50, 0.2, 0.5)
36 4.428690551393267
37 >>> terminal_velocity(-5, 50, -0.2, -2)
38 Traceback (most recent call last):
39 ...
40 ValueError: mass, density, area and the drag coefficient all need to be positive
41 >>> terminal_velocity(3, -20, -1, 2)
42 Traceback (most recent call last):
43 ...
44 ValueError: mass, density, area and the drag coefficient all need to be positive
45 >>> terminal_velocity(-2, -1, -0.44, -1)
46 Traceback (most recent call last):
47 ...
48 ValueError: mass, density, area and the drag coefficient all need to be positive
49 """
50 if mass <= 0 or density <= 0 or area <= 0 or drag_coefficient <= 0:
51 raise ValueError(
52 "mass, density, area and the drag coefficient all need to be positive"
53 )
54 return ((2 * mass * g) / (density * area * drag_coefficient)) ** 0.5
55
56
57if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected