Skip to content

Added Orbital Period Algorithm in Physics#14580

Open
MSameer404 wants to merge 3 commits intoTheAlgorithms:masterfrom
MSameer404:orbital_period
Open

Added Orbital Period Algorithm in Physics#14580
MSameer404 wants to merge 3 commits intoTheAlgorithms:masterfrom
MSameer404:orbital_period

Conversation

@MSameer404
Copy link
Copy Markdown

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Apr 25, 2026
@algorithms-keeper algorithms-keeper Bot added the tests are failing Do not merge until tests pass label Apr 25, 2026
Comment thread physics/orbital_period.py
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))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread physics/orbital_period.py
"""
Calculate the time period of a satellite orbiting a celestial body

>>> time_period_of_satellite(5.972e24, 6.371e6, 3.5e5)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of realistic Earth values 👍 Consider explicitly mentioning units (kg, meters) in the docstring examples to avoid ambiguity for users.

Comment thread physics/orbital_period.py
...
ValueError: Height must be a non-negative value
"""
if mass <= 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good validation checks 👍 Consider grouping these validations into a single block or helper function for better readability and maintainability.

Comment thread physics/orbital_period.py
if height < 0:
raise ValueError("Height must be a non-negative value")

import math
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be placed at the top of the file according to Python style guidelines (PEP8). Consider moving this import to the top.

Comment thread physics/orbital_period.py

import math

return round(2 * math.pi * ((radius + height) ** 3 / (6.674e-11 * mass)) ** 0.5, 2)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread physics/orbital_period.py

import math

return round(2 * math.pi * ((radius + height) ** 3 / (6.674e-11 * mass)) ** 0.5, 2)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rounding inside the function may limit flexibility. Consider returning the raw value and letting the caller decide the precision.

Comment thread physics/orbital_period.py
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants