1+ """
2+ The time period of a satellite is the time taken by a satellite to
3+ complete one full orbit around a celestial body.
4+
5+ T = 2π * sqrt((R + h)^3 / (G * M))
6+
7+ G is the Universal Gravitational Constant and equals 6.674 × 10^-11 N m²/kg²
8+ M is the mass of the celestial body (kg)
9+ R is the radius of the celestial body (m)
10+ h is the height of the satellite above the surface (m)
11+
12+ Reference: https://en.wikipedia.org/wiki/Orbital_period
13+ """
14+
15+
16+ def time_period_of_satellite (mass : float , radius : float , height : float ) -> float :
17+ """
18+ Calculate the time period of a satellite orbiting a celestial body
19+
20+ >>> time_period_of_satellite(5.972e24, 6.371e6, 3.5e5)
21+ 5562.65
22+ >>> time_period_of_satellite(5.972e24, 6.371e6, 0)
23+ 5060.84
24+ >>> time_period_of_satellite(7.342e22, 1.737e6, 1.0e5)
25+ 7045.95
26+ >>> time_period_of_satellite(6.39e23, 3.389e6, 3.0e5)
27+ 7113.64
28+ >>> time_period_of_satellite(-5.972e24, 6.371e6, 3.5e5)
29+ Traceback (most recent call last):
30+ ...
31+ ValueError: Mass must be a positive value
32+ >>> time_period_of_satellite(5.972e24, -6.371e6, 3.5e5)
33+ Traceback (most recent call last):
34+ ...
35+ ValueError: Radius must be a positive value
36+ >>> time_period_of_satellite(5.972e24, 6.371e6, -3.5e5)
37+ Traceback (most recent call last):
38+ ...
39+ ValueError: Height must be a non-negative value
40+ """
41+ if mass <= 0 :
42+ raise ValueError ("Mass must be a positive value" )
43+ if radius <= 0 :
44+ raise ValueError ("Radius must be a positive value" )
45+ if height < 0 :
46+ raise ValueError ("Height must be a non-negative value" )
47+
48+ import math
49+ return round (2 * math .pi * ((radius + height ) ** 3 / (6.674e-11 * mass )) ** 0.5 , 2 )
50+
51+
52+ if __name__ == "__main__" :
53+ import doctest
54+
55+ doctest .testmod ()
0 commit comments