-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathdo_stats.py
More file actions
80 lines (54 loc) · 2.16 KB
/
Copy pathdo_stats.py
File metadata and controls
80 lines (54 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
do_stats.py - example project to calculate statistics
Date: January 2025
"""
#####################################
# Imports At the Top
#####################################
# Import from Python Standard Library for mathematical statistics
import statistics
# Import from local project modules
# Most projects will have a custom logger - you can use ours as is in any project
from utils_logger import logger
#####################################
# Define Reusable Functions
#####################################
def calculate_min(scores: list) -> float:
"""Return the minimum value in the list."""
return min(scores)
def calculate_max(scores: list) -> float:
"""Return the maximum value in the list."""
return max(scores)
def calculate_mean(scores: list) -> float:
"""Return the mean (average) of the list."""
return statistics.mean(scores)
def calculate_standard_deviation(scores: list) -> float:
"""Return the standard deviation of the list."""
return statistics.stdev(scores)
#####################################
# Define main Function
#####################################
def main(scores: list) -> None:
"""
Main function to calculate and log statistics for a given list of scores.
Args:
scores (list): A list of numbers to calculate statistics for.
"""
logger.info("Starting MAIN function.")
# Calculate and log each statistic
logger.info(f"Scores: {scores}")
logger.info(f"Minimum: {calculate_min(scores):.2f}")
logger.info(f"Maximum: {calculate_max(scores):.2f}")
logger.info(f"Mean: {calculate_mean(scores):.2f}")
logger.info(f"Standard Deviation: {calculate_standard_deviation(scores):.2f}")
logger.info("Exiting MAIN function.")
#####################################
# Conditional Execution (run if this file is executed)
#####################################
if __name__ == "__main__":
logger.info("STATS - Ready for work.")
# Provide a default list of scores for the program to analyze
DEFAULT_SCORES = [3.5, 4.0, 4.8, 2.9, 3.7, 4.3, 3.8]
# Call the main function with the default scores
main(DEFAULT_SCORES)
logger.info("STATS - Execution complete.")