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. /Brightness in code
Space Science and AstronomyMediumHigh School (9–10)Telescopes, Detectors and Magnitudes

Brightness in code

You will write three small functions about the brightness of stars.

The idea. For two stars of equal luminosity, b1/b2=(d2/d1)2b_1/b_2 = (d_2/d_1)^2b1​/b2​=(d2​/d1​)2. A step of 555 magnitudes is a factor of 100100100 in brightness. The distance modulus is m−M=5log⁡10(d/10)m - M = 5\log_{10}(d/10)m−M=5log10​(d/10), with ddd in parsecs.

Your tasks.

  1. In brightness_ratio, return b1/b2b_1/b_2b1​/b2​ for two stars of equal luminosity at distances d1 and d2.
  2. In magnitude_ratio, return how many times brighter a star is that is dm magnitudes brighter than another.
  3. In distance_pc, return the distance in parsecs from the apparent magnitude m and the absolute magnitude 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 how far away a star is that has m=6.0m = 6.0m=6.0 and M=1.0M = 1.0M=1.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
← Waves of the spectrumReading a star's light →
More onTelescopes, Detectors and Magnitudes

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. Binary stars and remnants in codeMedium
  2. The life of a star in codeEasy
  3. Reading a star's lightMedium
  4. Waves of the spectrumEasy
  5. A telescope calculatorMedium
All labs on this topic →