HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /An orbit step by step
Space Science and AstronomyAdvancedHigh School (11–12)Celestial Mechanics and Spaceflight

An orbit step by step

You will move a planet round the Sun in small time steps and check that its energy and angular momentum stay the same. Distances are in AU, speeds in km/s, time in seconds; GM=887.3 AU km2/s2GM = 887.3\ \text{AU km}^2/\text{s}^2GM=887.3 AU km2/s2. One AU is 1.496×108 km1.496 \times 10^8\ \text{km}1.496×108 km.

The idea. The acceleration points at the Sun: a⃗=−GMr⃗/r3\vec{a} = -GM\vec{r}/r^3a=−GMr/r3. The leapfrog method takes a half step in velocity, a full step in position, and another half step in velocity. It keeps the energy steady over many orbits.

Your tasks.

  1. In acceleration, return the two parts of the acceleration, in km/s per second, at the point (x, y) in AU.
  2. In step, carry out one leapfrog step of length dt seconds.
  3. In energy, return the energy per kilogram, v2/2−GM/rv^2/2 - GM/rv2/2−GM/r, in km2/s2\text{km}^2/\text{s}^2km2/s2.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, start the planet at 1 AU1\ \text{AU}1 AU with 35 km/s35\ \text{km/s}35 km/s and compare its farthest distance with the vis-viva value.

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← What kind of orbit is it?A Hohmann transfer planner →
More onCelestial Mechanics and Spaceflight

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. Finding L1 by bisectionAdvanced
  2. A Hohmann transfer plannerHard
  3. What kind of orbit is it?Hard
  4. A Kepler's equation solverHard
  5. Orbits from their two endsHard
All labs on this topic →