MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / total_time

Function total_time

physics/horizontal_projectile_motion.py:108–135  ·  view source on GitHub ↗

r""" Returns total time of the motion Formula: .. math:: \frac{2 v_0 \cdot \sin (\alpha)}{g} v_0 - \text{initial velocity} \alpha - \text{angle} >>> total_time(30, 45) 4.33 >>> total_time(100, 78) 19.95 >>> total_time(-10, 4

(init_velocity: float, angle: float)

Source from the content-addressed store, hash-verified

106
107
108def total_time(init_velocity: float, angle: float) -> float:
109 r"""
110 Returns total time of the motion
111
112 Formula:
113 .. math::
114 \frac{2 v_0 \cdot \sin (\alpha)}{g}
115
116 v_0 - \text{initial velocity}
117
118 \alpha - \text{angle}
119
120 >>> total_time(30, 45)
121 4.33
122 >>> total_time(100, 78)
123 19.95
124 >>> total_time(-10, 40)
125 Traceback (most recent call last):
126 ...
127 ValueError: Invalid velocity. Should be a positive number.
128 >>> total_time(30, "b")
129 Traceback (most recent call last):
130 ...
131 TypeError: Invalid angle. Should be an integer or float.
132 """
133 check_args(init_velocity, angle)
134 radians = deg_to_rad(angle)
135 return round(2 * init_velocity * sin(radians) / g, 2)
136
137
138def test_motion() -> None:

Callers 2

test_motionFunction · 0.85

Calls 2

sinFunction · 0.90
check_argsFunction · 0.85

Tested by 1

test_motionFunction · 0.68