Code

Summarize the Soundings

The statistics module sums up a list of numbers for you.

import statistics

depths = [2, 4, 4, 5, 9]
statistics.mean(depths)     # 4.8      (the average)
statistics.median(depths)   # 4        (the middle value)
statistics.mode(depths)     # 4        (the most common)
statistics.stdev(depths)    # 2.588... (how spread out)
  • The mean adds everything up and divides by how many there are.
  • The median sorts the numbers and takes the middle one. With an even count, it averages the two middle numbers.
  • The mode is the value that appears most often. It works on words too!
  • The standard deviation (stdev) measures spread. Small means the numbers are close together. Big means they are far apart.

Assignment

  1. depth_summary(depths): return a dict with three keys:
    • "mean": the mean, rounded to 1 decimal place,
    • "median": the median,
    • "spread": the statistics.stdev, rounded to 2 decimals.
  2. usual_catch(fish): fish is a list of fish names. Return the most common one with statistics.mode.