Skip to content

Commit 0ca5e82

Browse files
committed
imported the value of g from scipy and changed the doctests accordingly
1 parent e21bbaa commit 0ca5e82

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: physics/terminal_velocity.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from scipy.constants import g
12
"""
23
Title : Computing the terminal velocity of an object falling
34
through a fluid.
@@ -13,7 +14,7 @@
1314
where :
1415
Vt = Terminal velocity (in m/s)
1516
m = Mass of the falling object (in Kg)
16-
g = Acceleration due to gravity (value taken : 9.8 m/s^2)
17+
g = Acceleration due to gravity (value taken : imported from scipy)
1718
ρ = Density of the fluid through which the object is falling (in Kg/m^3)
1819
A = Projected area of the object (in m^2)
1920
Cd = Drag coefficient (dimensionless)
@@ -27,11 +28,11 @@ def terminal_velocity(
2728
) -> float:
2829
"""
2930
>>> terminal_velocity(1, 25, 0.6, 0.77)
30-
1.3026778945578592
31+
1.3031197996044768
3132
>>> terminal_velocity(2, 100, 0.45, 0.23)
32-
1.9461345311993645
33+
1.9467947148674276
3334
>>> terminal_velocity(5, 50, 0.2, 0.5)
34-
4.427188724235731
35+
4.428690551393267
3536
>>> terminal_velocity(-5, 50, -0.2, -2)
3637
Traceback (most recent call last):
3738
...
@@ -49,7 +50,7 @@ def terminal_velocity(
4950
raise ValueError(
5051
"mass, density, area and the drag coefficient all need to be positive"
5152
)
52-
return ((2 * mass * 9.8) / (density * area * drag_coefficient)) ** 0.5
53+
return ((2 * mass * g) / (density * area * drag_coefficient)) ** 0.5
5354

5455

5556
if __name__ == "__main__":

0 commit comments

Comments
 (0)