Averages
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:
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:
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:
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:
Next Exercise: Hip to Be Square