Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to find mean, median, and mode in python

+1 vote
asked Sep 23, 2019 by anonymous

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:

userList = [3, 1, 7, 1, 4, 10]

1 Answer

0 votes
answered Sep 28, 2019 by KoushikKaleru (220 points)

You can directly use formulae for calculating them 

But we can do it with predefined functions by importing statistics and scipy modules

#Program

import statistics as st
from scipy import stats
userList = [3, 1, 7, 1, 4, 10]
print("Mean:" ,st.mean(userList))
print("Median:" ,st.median(userList))
print("Mode:", stats.mode(userList))

 

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...