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
  • 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. /Distances to the stars in code
PhysicsMediumHigh School (11–12)Astrophysics

Distances to the stars in code

You will write three small functions that turn measurements into distances. Distances are in parsecs.

The idea. A parallax ppp in arcseconds gives d=1/pd = 1/pd=1/p. A star of luminosity LLL gives the flux F=L/(4πd2)F = L/(4\pi d^2)F=L/(4πd2) at a distance ddd in metres. The distance modulus is m−M=5log⁡10(d/10 pc)m - M = 5\log_{10}(d/10\ \text{pc})m−M=5log10​(d/10 pc).

Your tasks.

  1. In from_parallax, return the distance in parsecs for a parallax in milliarcseconds.
  2. In flux, return the flux in W/m2\text{W/m}^2W/m2 for a luminosity in watts and a distance in parsecs.
  3. In from_magnitudes, return the distance in parsecs from m and M.

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, find the distance of a star with m=15.0m = 15.0m=15.0 and M=0.0M = 0.0M=0.0.

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
← Dose in codeStars as black bodies in code →
More onAstrophysics

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Luminosity, flux and the magnitude scaleMeasuring Stars: Distance, Luminosity and Temperature

More labs on this topic

  1. The early universe in codeMedium
  2. Hubble's law in codeMedium
  3. Finding exoplanets in codeMedium
  4. Main-sequence stars in codeMedium
Stars as black bodies in codeMedium
All labs on this topic →