Python program: Average, median and spread of a list
Summarise a list of numbers.
The code
import statistics as st scores = [72, 88, 95, 61, 77, 84, 90] print("mean: ", round(sum(scores) / len(scores), 2)) print("median:", st.median(scores)) print("stdev: ", round(st.stdev(scores), 2)) print("range: ", max(scores) - min(scores))
Output
mean: 81.0 median: 84 stdev: 11.78 range: 34
How it works
The mean is the total divided by the count. The statistics module adds the median and standard deviation.
Python features used
Learn the ideas behind it in the free lesson Modules & the Standard Library.