# statistics — What Your Data Is Telling You
# mean, median, mode, stdev — no formula needed
# redhorndev.com

import statistics

scores = [85, 74, 91, 63, 98, 74, 85]

# ─────────────────────────────────────────────
# The center
# ─────────────────────────────────────────────

print(statistics.mean(scores))          # 81.43 — average
print(statistics.median(scores))        # 85    — middle value
print(statistics.mode(scores))          # 74    — most frequent

# mode() raises StatisticsError if no value repeats
# use multimode() to be safe
print(statistics.multimode(scores))     # [74, 85] — all most frequent

unique = [1, 2, 3, 4, 5]
# statistics.mode(unique)               # StatisticsError
print(statistics.multimode(unique))     # [1, 2, 3, 4, 5] — no error

# ─────────────────────────────────────────────
# The spread
# ─────────────────────────────────────────────

scores = [85, 74, 91, 63, 98]

print(statistics.stdev(scores))         # 13.28 — standard deviation
print(statistics.variance(scores))      # 176.3 — variance

# stdev — how far values typically are from the mean
# low stdev = clustered together
# high stdev = spread out

# ─────────────────────────────────────────────
# Practical — full picture of a dataset
# ─────────────────────────────────────────────

squad_scores = [85, 74, 91, 63, 98, 77, 88]

print(f"Mean:   {statistics.mean(squad_scores):.1f}")
print(f"Median: {statistics.median(squad_scores)}")
print(f"Stdev:  {statistics.stdev(squad_scores):.1f}")
print(f"Min:    {min(squad_scores)}")       # built-in — no import
print(f"Max:    {max(squad_scores)}")       # built-in — no import

# Mean:   82.3
# Median: 85
# Stdev:  11.8
# Min:    63
# Max:    98

# ─────────────────────────────────────────────
# Works with floats too
# ─────────────────────────────────────────────

temps = [36.6, 37.1, 36.8, 38.2, 36.9]
print(f"Average temp: {statistics.mean(temps):.2f}")    # 37.12
print(f"Median temp:  {statistics.median(temps)}")      # 36.9

# ─────────────────────────────────────────────
# Quick reference
# ─────────────────────────────────────────────

# import statistics
#
# statistics.mean(lst)        — average
# statistics.median(lst)      — middle value
# statistics.mode(lst)        — most frequent (StatisticsError if all unique)
# statistics.multimode(lst)   — all most frequent, no error
# statistics.stdev(lst)       — standard deviation
# statistics.variance(lst)    — variance
#
# min(lst) and max(lst) are built-ins — no import needed
