Statistics
You're an intern at a rapidly growing tech start-up. They've recently developed a web application for data analysis, and a crucial part of it is calculating statistics. As they've been growing, the application's code base has become quite large, and it's time to start organizing things better. Your task for the week is to create a Python module called
statistics_calculator
that contains functions to calculate the mean, median, mode, and standard deviation of a list of numbers.You should structure your code as follows: Create separate files for each of the statistics, with their respective calculation function. These files should be:
mean.py
: Contains a functioncalculate_mean
to calculate the mean.
median.py
: Contains a functioncalculate_median
to calculate the median.
mode.py
: Contains a functioncalculate_mode
to calculate the mode (in case there are several most frequent numbers the function should return the smallest one).
std_dev.py
: Contains a functioncalculate_std_dev
to calculate the standard deviation.
Each of these files should be within a directory named
statistics_calculator
. Finally, import all these functions in the statistics_calculator/__init__.py
file so that other parts of the application can access these functions without additional imports.The input and output are handled automatically by the
main.py
module.Your code structure should look like this:
statistics_calculator/
├── __init__.py
├── mean.py
├── median.py
├── mode.py
└── std_dev.py
Input | Output |
a=[2, 2, 3, 5, 7, 5, 7, 5, 2, 2];
print(calculate_mean(a));
print(calculate_median(a));
print(calculate_mode(a));
print(calculate_std_dev(a)) | 4.0
4.0
2
2.05480467 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB