Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 680cc1f

Browse files
committed
Simple Statistics
1 parent cd6dd1d commit 680cc1f

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ files, and the full tutorial for each collection of code is available below.
2727
20. [Json In Python](https://vegibit.com/python-json-tutorial/)
2828
21. [XML Parsing](https://vegibit.com/python-xml-parsing/)
2929
22. [Beautiful Soup Web Scraping](https://vegibit.com/python-web-scraping-with-beautiful-soup/)
30-
23. [Selenium Python Tutorial](https://vegibit.com/selenium-python-tutorial/)
30+
23. [Selenium Python Tutorial](https://vegibit.com/selenium-python-tutorial/)
31+
24. [Simple Statistics](https://vegibit.com/python-statistics-tutorial/)

simplestatistics.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)