How to find the mean

This post will cover how to find the mean (also called average) from a set of numbers. We’ll then implement a solution in the python programming language!

For this example we will find the mean for this set of numbers:

5,6,7,2,6,9,30,1

Step1: Add all the numbers together:

5+6+7+2+6+9+30+1 = 66

Step2: Count how many numbers we added together 5,6,7,2,6,9,30,1. There is a total of 8 numbers.

Step3: We then divide the sum of the numbers (66) by how many numbers there are (8).

66 / 8 = 8.25

The mean or average for 5,6,7,2,6,9,30,1 is 8.25

Finding the mean with Python:

Seeing how to do it from scratch will probably help you understand how to implement the math, but you can actuallt use a mean function from Pythons statistics library. Read about it here

Mean from scratch:

# Take a list of numbers and return the mean
def findMean(numbers):
    mean = sum(numbers) / len(numbers)
    print(mean)

#Run the function and provide list of numbers 
findMean([2,4,5,6,7])
# Take a list of numbers and return the mean
def findMean(numbers):
    mean = sum(numbers) / len(numbers)
    print(mean)

#Run the function and provide list of numbers 
findMean([2,4,5,6,7])
-
If you have any questions about this post or want to stay connected find me at:

Email Github Twitter LinkedIn