|
| 1 | +import statistics |
| 2 | +import math |
| 3 | + |
| 4 | +grades = [80, 85, 77, 97, 100, 75, 88, 90, 93] |
| 5 | + |
| 6 | +# Mean |
| 7 | +# Here is how we calculate the mean(average) of all the grades in our list. |
| 8 | + |
| 9 | +meangrades = statistics.mean(grades) |
| 10 | +print(f'The mean of all the grades is {meangrades}') |
| 11 | + |
| 12 | + |
| 13 | +# Median |
| 14 | +# To calculate the Median, or midpoint of the grades, we’ll use this code here. |
| 15 | +mediangrades = statistics.median(grades) |
| 16 | +print(f'The median of all the grades is {mediangrades}') |
| 17 | + |
| 18 | +# Sort to view the "middle" |
| 19 | +print(sorted(grades)) |
| 20 | + |
| 21 | + |
| 22 | +# Now we can do the calculation of the mode like so. |
| 23 | +grades = [75, 80, 85, 77, 97, 100, 75, 88, 75, 90, 93, 77] |
| 24 | +modegrades = statistics.mode(grades) |
| 25 | +print(f'The mode of all the grades is {modegrades}') |
| 26 | + |
| 27 | + |
| 28 | +# Variance |
| 29 | +grades = [75, 80, 85, 77, 97, 100, 75, 88, 75, 90, 93, 77] |
| 30 | +variancegrades = statistics.variance(grades) |
| 31 | + |
| 32 | +print(f'The grades have a variance of {variancegrades}') |
| 33 | + |
| 34 | +grades = [90, 90, 90, 90, 90, 90] |
| 35 | +variancegrades = statistics.variance(grades) |
| 36 | + |
| 37 | +print(f'The grades have a variance of {variancegrades}') |
| 38 | + |
| 39 | +grades = [90, 90, 90, 90, 90, 90, 100] |
| 40 | +variancegrades = statistics.variance(grades) |
| 41 | +print(f'The grades have a variance of {variancegrades}') |
| 42 | + |
| 43 | +grades = [80, 82, 100, 77, 89, 94, 98, 50] |
| 44 | +variancegrades = statistics.variance(grades) |
| 45 | +print(f'The grades have a variance of {variancegrades}') |
| 46 | + |
| 47 | + |
| 48 | +# Standard Deviation |
| 49 | +grades = [89, 91, 95, 92, 93, 94, 98, 90] |
| 50 | +stdevgrades = statistics.stdev(grades) |
| 51 | + |
| 52 | +print(f'The grades have a standard deviation of {stdevgrades}') |
| 53 | + |
| 54 | +grades = [30, 80, 100, 45, 15, 94, 64, 90] |
| 55 | +stdevgrades = statistics.stdev(grades) |
| 56 | + |
| 57 | +print(f'The grades have a standard deviation of {stdevgrades}') |
| 58 | + |
| 59 | +grades = [30, 80, 100, 45, 15, 94, 64, 90] |
| 60 | +stdevgrades = math.sqrt(statistics.variance(grades)) |
| 61 | + |
| 62 | +print(f'The grades have a standard deviation of {stdevgrades}') |
0 commit comments