Python: A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set of numbers. Define these functions, median and mode, in a module named stats.py. Also include a function named mean, which computes the average of a set of numbers. Each function should expect a list of numbers as an argument and return a single number. Each function should return 0 if the list is empty. Include a main function that tests the three statistical functions using the following list defined in main: lyst = [3, 1, 7, 1, 4, 10] An example of the program output is shown below: List: [3, 1, 7, 1, 4, 10] Mode: 1 Median: 3.5 Mean: 4.33333333333333 This is the code they gave me, but something is wrong or something is missing. from statistics import median def mode(lyst): fv = {} for v in lyst: fv[v] = fv.get(v, 0) + 1 mf = max(fv.values()) md = [key for key, v in fv.items() if v == mf] return md[0] lyst = [3,1,7,1,4,10] print ("List:",lyst) print("Mode: ",mode(lyst)) total = 0 Median = median(lyst) print("Median: ",Median) for i in lyst: total = total +i mean = total/len(lyst) print("Mean: ",mean)
Python:
A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set of numbers. Define these functions, median and mode, in a module named stats.py. Also include a function named mean, which computes the average of a set of numbers. Each function should expect a list of numbers as an argument and return a single number. Each function should return 0 if the list is empty. Include a main function that tests the three statistical functions using the following list defined in main:
lyst = [3, 1, 7, 1, 4, 10]
An example of the program output is shown below:
List: [3, 1, 7, 1, 4, 10]
Mode: 1
Median: 3.5
Mean: 4.33333333333333
This is the code they gave me, but something is wrong or something is missing.
from statistics import median
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images