Skip to content

Commit 30fcdd4

Browse files
authored
Update escape_velocity.py
1 parent 87f4e8c commit 30fcdd4

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

physics/escape_velocity.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,23 @@ def escape_velocity(mass: float, radius: float) -> float:
2626
float: Escape velocity in meters per second, rounded to 3 decimal places.
2727
2828
Examples:
29-
>>> escape_velocity(5.972e24, 6.371e6) # Earth
29+
>>> escape_velocity(mass=5.972e24, radius=6.371e6) # Earth
3030
11185.978
31-
>>> escape_velocity(7.348e22, 1.737e6) # Moon
31+
>>> escape_velocity(mass=7.348e22, radius=1.737e6) # Moon
3232
2376.307
33-
>>> escape_velocity(1.898e27, 6.9911e7) # Jupiter
33+
>>> escape_velocity(mass=1.898e27, radius=6.9911e7) # Jupiter
3434
60199.545
35-
>>> escape_velocity(0, 1.0)
35+
>>> escape_velocity(mass=0, radius=1.0)
3636
0.0
37-
>>> escape_velocity(1.0, 0)
37+
>>> escape_velocity(mass=1.0, radius=0)
3838
Traceback (most recent call last):
3939
...
4040
ZeroDivisionError: Radius cannot be zero.
4141
"""
42-
gravitational_constant = 6.67430e-11
42+
gravitational_constant = 6.67430e-11 # m^3 kg^-1 s^-2
4343

4444
if radius == 0:
4545
raise ZeroDivisionError("Radius cannot be zero.")
46-
if mass == 0:
47-
return 0.0
4846

4947
velocity = math.sqrt(2 * gravitational_constant * mass / radius)
5048
return round(velocity, 3)
@@ -57,10 +55,10 @@ def escape_velocity(mass: float, radius: float) -> float:
5755
print("Calculate escape velocity of a celestial body...\n")
5856

5957
try:
60-
mass = float(input("Enter mass of the celestial body (in kg): ").strip())
61-
radius = float(input("Enter radius from center (in meters): ").strip())
58+
mass = float(input("Enter mass of the celestial body (in kgs): ").strip())
59+
radius = float(input("Enter radius from the center of mass (in ms): ").strip())
6260

63-
velocity = escape_velocity(mass, radius)
61+
velocity = escape_velocity(mass=mass, radius=radius)
6462
print(f"Escape velocity is {velocity} m/s")
6563

6664
except ValueError:

0 commit comments

Comments
 (0)