How to do it...

Note that the import statement is omitted in the following screenshots:

  1. The mean(data) function returns the normal average of a sequence or iterator:

    • The line 3 is the mean of integers.
    • The line 4 is the mean of floats.
    • The lines 6 and line 8 show that fractions can be averaged, as well as decimals.
  1. The harmonic_mean(data) function returns the harmonic average of a sequence or iterator. The harmonic mean is the reciprocal of the arithmetic mean of the reciprocals of the argument and is typically used when the average of rates or rations is needed.

For example, if a car traveled for a given distance at 60 mph, then ...

Get Secret Recipes of the Python Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.