
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
depth_summary(depths): return a dict with three keys:"mean": the mean, rounded to 1 decimal place,"median": the median,"spread": thestatistics.stdev, rounded to 2 decimals.
usual_catch(fish):fishis a list of fish names. Return the most common one withstatistics.mode.
depth_summary(depths): return a dict with three keys:"mean": the mean, rounded to 1 decimal place,"median": the median,"spread": thestatistics.stdev, rounded to 2 decimals.
usual_catch(fish):fishis a list of fish names. Return the most common one withstatistics.mode.
main.py Python sleeping
Press Run to try your code, then Check to test it.