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 is never below the geometric mean , and is never below the harmonic mean . Computers round, so the test allows a tiny tolerance of 1e-9.
Your tasks.
am(nums), the arithmetic mean.gm(nums), the geometric mean. Use math.prod(nums) ** (1 / len(nums)).hm(nums), the harmonic mean: the length of the list divided by the sum of the reciprocals.in_order(nums). Return True when am >= gm - 1e-9 and gm >= hm - 1e-9.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 join the discussion.
Loading…