Averages

The questions below are due on Thursday July 01, 2021; 11:00:00 AM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

In this problem, we will consider two different ways of averaging sets of numbers: the arithmetic mean and the geometric mean.

Part 1: Arithmetic Mean

The arithmetic mean of a list of n numbers a_1, a_2, \ldots, a_n is the sum of the numbers divided by n:

\frac{\sum_{k=1}^n a_k}{n} = \frac{a_1+a_2+\ldots+a_n}{n}

Write a function arith_mean(numbers) to compute the arithmetic mean of a list of numbers (which could be either ints or floats). One thing to watch out for is an empty list as input. It's not clear that any numeric answer makes sense here. You should return None in that case.

Unlike in other file submission questions you don't need to define input variables at the top. Instead you just need to define the function arith_mean. That means your code might look like:

def arith_mean(numbers):
    # code here with a return statement

You may use Python's sum function, but no additional imports. Submit your file for checking below:

  No file selected

Part 2: Geometric Mean

The geometric mean of a list of n numbers is the product of the numbers, raised to the power 1/n:

\left(\prod_{k=1}^n a_k\right)^{\frac{1}{n}} = \sqrt[n]{a_1a_2\ldots a_n}

Write a function geo_mean(numbers) to compute the geometric mean of a list of numbers (which could be either ints or floats). As in Part 1, your function should return None in the case of an empty input list.

Submit your file for checking below:

  No file selected

Next Exercise: Hip to Be Square

Back to exercises