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 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
Python def averagevals method mean if method mean return sumvals lenvals elif ... View full answer
Get step-by-step solutions from verified subject matter experts
