+91 81900 98289

Statistics Module

This Statistics Module lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

statistics.mean, median, mode, pstdev, and stdev describe a list of numbers.

They are part of Python. You do not install them.

Example 1: Start here

pstdev is for a full set. stdev is for a sample.

import statistics # load a tool that comes with Python marks = [71, 82, 82, 90] # a list; the values stay in this order print(statistics.mean(marks)) print(statistics.median(marks))

Example 2: Store the idea in a name

Statistics Module begins with a value you can point at. The name topic holds that text.

topic = "Statistics Module" # text print(topic)

Example 3: Check it with if

An if chooses one branch. Change the score and run it again to see the other message.

score = 34 # a whole number if score >= 80: # run the indented lines only when this is true print("Pass") else: # runs when the test above was false print("Try again")

Example 4: Repeat with a loop

A for loop runs the indented line once per step. The numbers 1, 2, and 3 are printed on their own lines.

for step in range(1, 4): # repeat once per number; range stops before the last print("Step", step) # a comma prints each value, with a space between
pstdev is for a full set. stdev is for a sample.
Call Now 81900 98289