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. /Three means and their order
MathematicsMediumHigh School (11–12)Inequalities and the AM, GM and HM Means

Three means and their order

You will write the three classical means and a test of the chain between them. The checker tries lists of different sizes, a list of equal numbers and a list with one very large number.

The idea. For positive numbers the arithmetic mean AAA is never below the geometric mean GGG, and GGG is never below the harmonic mean HHH. Computers round, so the test allows a tiny tolerance of 1e-9.

Your tasks.

  1. Finish am(nums), the arithmetic mean.
  2. Finish gm(nums), the geometric mean. Use math.prod(nums) ** (1 / len(nums)).
  3. Finish hm(nums), the harmonic mean: the length of the list divided by the sum of the reciprocals.
  4. Finish in_order(nums). Return True when am >= gm - 1e-9 and gm >= hm - 1e-9.

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, try in_order([5, -1, 2]). What does the geometric mean give for a list with a negative number?

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
← Pythagorean triples by formula and by searchLeast values by search and by AM-GM →
More onInequalities and the AM, GM and HM Means

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Arithmetic, geometric and harmonic meansThe AM-GM-HM Inequality and Power Means

More labs on this topic

  1. The point that minimises total distanceMedium
  2. Convexity on a gridMedium
  3. Best and worst pairingsMedium
  4. Testing Cauchy-SchwarzMedium
Least values by search and by AM-GMMedium
All labs on this topic →