Question: Write a function average(vals, method) that calculates the mean or median of a list of numbers, depending on the value of a second argument

Write a function average(vals, method) that calculates the mean or median of a list of numbers, depending on

Write a function average(vals, method) that calculates the mean or median of a list of numbers, depending on the value of a second argument method that takes the value "mean" or "median". The default should be "mean". Test it with some lists for which you can predict the answer, and show your testing in your notebook. NB use core Python only. Do NOT use numpy! # Example test: test = [1,2,3,4,5] average (test, method='mean') average (test, method='median') i

Step by Step Solution

3.37 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python def averagevals method mean if method mean return sumvals lenvals elif ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!