Added Orbital Period Algorithm in Physics#14580
Added Orbital Period Algorithm in Physics#14580MSameer404 wants to merge 3 commits intoTheAlgorithms:masterfrom
Conversation
6474d11 to
0b2f0f3
Compare
for more information, see https://pre-commit.ci
| 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)) |
There was a problem hiding this comment.
Consider formatting the formula using consistent mathematical notation (e.g., with proper spacing or LaTeX-style formatting) to improve readability, especially since this is a physics-related implementation.
| """ | ||
| Calculate the time period of a satellite orbiting a celestial body | ||
|
|
||
| >>> time_period_of_satellite(5.972e24, 6.371e6, 3.5e5) |
There was a problem hiding this comment.
Nice use of realistic Earth values 👍 Consider explicitly mentioning units (kg, meters) in the docstring examples to avoid ambiguity for users.
| ... | ||
| ValueError: Height must be a non-negative value | ||
| """ | ||
| if mass <= 0: |
There was a problem hiding this comment.
Good validation checks 👍 Consider grouping these validations into a single block or helper function for better readability and maintainability.
| if height < 0: | ||
| raise ValueError("Height must be a non-negative value") | ||
|
|
||
| import math |
There was a problem hiding this comment.
Imports should be placed at the top of the file according to Python style guidelines (PEP8). Consider moving this import to the top.
|
|
||
| import math | ||
|
|
||
| return round(2 * math.pi * ((radius + height) ** 3 / (6.674e-11 * mass)) ** 0.5, 2) |
There was a problem hiding this comment.
This expression is correct but a bit hard to read. Consider breaking it into intermediate variables (e.g., orbital_radius, gravitational_term) to improve clarity and maintainability.
|
|
||
| import math | ||
|
|
||
| return round(2 * math.pi * ((radius + height) ** 3 / (6.674e-11 * mass)) ** 0.5, 2) |
There was a problem hiding this comment.
Rounding inside the function may limit flexibility. Consider returning the raw value and letting the caller decide the precision.
There was a problem hiding this comment.
Overall, this is a well-structured implementation with clear validation and useful doctests. A few improvements around readability, constants, and style (imports placement, expression clarity) would make it production-quality.
Describe your change:
Checklist: