From e0d5ed0d3cc15088f43ef24a33bb40c54dd00444 Mon Sep 17 00:00:00 2001 From: MohammadSameer-Dev Date: Sat, 25 Apr 2026 16:14:40 +0530 Subject: [PATCH 1/3] Added Orbital Period Algorithm in Physics --- physics/orbital_period.py | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 physics/orbital_period.py diff --git a/physics/orbital_period.py b/physics/orbital_period.py new file mode 100644 index 000000000000..33765467789f --- /dev/null +++ b/physics/orbital_period.py @@ -0,0 +1,55 @@ +""" +The time period of a satellite is the time taken by a satellite to +complete one full orbit around a celestial body. + +T = 2π * sqrt((R + h)^3 / (G * M)) + +G is the Universal Gravitational Constant and equals 6.674 × 10^-11 N m²/kg² +M is the mass of the celestial body (kg) +R is the radius of the celestial body (m) +h is the height of the satellite above the surface (m) + +Reference: https://en.wikipedia.org/wiki/Orbital_period +""" + + +def time_period_of_satellite(mass: float, radius: float, height: float) -> float: + """ + Calculate the time period of a satellite orbiting a celestial body + + >>> time_period_of_satellite(5.972e24, 6.371e6, 3.5e5) + 5562.65 + >>> time_period_of_satellite(5.972e24, 6.371e6, 0) + 5060.84 + >>> time_period_of_satellite(7.342e22, 1.737e6, 1.0e5) + 7045.95 + >>> time_period_of_satellite(6.39e23, 3.389e6, 3.0e5) + 7113.64 + >>> time_period_of_satellite(-5.972e24, 6.371e6, 3.5e5) + Traceback (most recent call last): + ... + ValueError: Mass must be a positive value + >>> time_period_of_satellite(5.972e24, -6.371e6, 3.5e5) + Traceback (most recent call last): + ... + ValueError: Radius must be a positive value + >>> time_period_of_satellite(5.972e24, 6.371e6, -3.5e5) + Traceback (most recent call last): + ... + ValueError: Height must be a non-negative value + """ + if mass <= 0: + raise ValueError("Mass must be a positive value") + if radius <= 0: + raise ValueError("Radius must be a positive value") + if height < 0: + raise ValueError("Height must be a non-negative value") + + import math + return round(2 * math.pi * ((radius + height) ** 3 / (6.674e-11 * mass)) ** 0.5, 2) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() \ No newline at end of file From 0b2f0f3a2a79b8001c2f7a3d3e004b93b8ff58d9 Mon Sep 17 00:00:00 2001 From: MohammadSameer-Dev Date: Sat, 25 Apr 2026 16:24:16 +0530 Subject: [PATCH 2/3] Fix ruff linting errors in orbital_period --- physics/orbital_period.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/physics/orbital_period.py b/physics/orbital_period.py index 33765467789f..3d56881d4f5f 100644 --- a/physics/orbital_period.py +++ b/physics/orbital_period.py @@ -4,7 +4,7 @@ T = 2π * sqrt((R + h)^3 / (G * M)) -G is the Universal Gravitational Constant and equals 6.674 × 10^-11 N m²/kg² +G is the Universal Gravitational Constant and equals 6.674 X 10^-11 N m²/kg² M is the mass of the celestial body (kg) R is the radius of the celestial body (m) h is the height of the satellite above the surface (m) @@ -52,4 +52,5 @@ def time_period_of_satellite(mass: float, radius: float, height: float) -> float if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod() + \ No newline at end of file From 5f4c6d64880397797953be9d3829d0ff4f52c18a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 25 Apr 2026 10:58:06 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/orbital_period.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/orbital_period.py b/physics/orbital_period.py index 3d56881d4f5f..05b8e52727d9 100644 --- a/physics/orbital_period.py +++ b/physics/orbital_period.py @@ -46,6 +46,7 @@ def time_period_of_satellite(mass: float, radius: float, height: float) -> float raise ValueError("Height must be a non-negative value") import math + return round(2 * math.pi * ((radius + height) ** 3 / (6.674e-11 * mass)) ** 0.5, 2) @@ -53,4 +54,3 @@ def time_period_of_satellite(mass: float, radius: float, height: float) -> float import doctest doctest.testmod() - \ No newline at end of file