|
| 1 | +# Average (Mean) |
| 2 | + |
| 3 | +Calculate the average of a list of numbers using mean. |
| 4 | + |
| 5 | +## Applications |
| 6 | + |
| 7 | +Calculating the mean of a list of numbers is one of the most common ways to |
| 8 | +determine the average of those numbers. |
| 9 | + |
| 10 | +Calculating a mean would be useful in these situations: |
| 11 | + |
| 12 | +- Determining the average score for all players of a video game level. |
| 13 | +- Finding the average grade for tests that a student took this semester. |
| 14 | +- Determining the average size of all files in a directory/folder. |
| 15 | + |
| 16 | +## Steps |
| 17 | + |
| 18 | +1. Input a list of numbers. |
| 19 | +2. Calculate the sum of all numbers in the list. |
| 20 | +3. Count the numbers in the list. |
| 21 | +4. Divide the sum by the total count of numbers in the list. |
| 22 | +5. Return mean. |
| 23 | + |
| 24 | +## Example |
| 25 | + |
| 26 | +Given the list `[2, 4, 6, 8, 20, 50, 70]`, let's calculate the average. |
| 27 | + |
| 28 | +### Step 1 |
| 29 | + |
| 30 | +Send `[2, 4, 6, 8, 20, 50, 70]` as input for a method/function. |
| 31 | + |
| 32 | +### Step 2 |
| 33 | + |
| 34 | +Add all the numbers together. |
| 35 | + |
| 36 | +`2 + 4 + 6 + 8 + 20 + 50 + 70 = 160`, so `sum = 160`. |
| 37 | + |
| 38 | +### Step 3 |
| 39 | + |
| 40 | +Count the numbers in the list. |
| 41 | + |
| 42 | +The list has seven numbers, so `count = 7`. |
| 43 | + |
| 44 | +### Step 4 |
| 45 | + |
| 46 | +Divide the sum of all the numbers by the count of the numbers. |
| 47 | + |
| 48 | +``` |
| 49 | +sum = 160 |
| 50 | +count = 7 |
| 51 | +``` |
| 52 | +If we ignore significant digits: `sum / count = `22.<u>857142</u> |
| 53 | + |
| 54 | +If we properly consider significant digits: `sum / count = 23` |
| 55 | + |
| 56 | +### Step 5 |
| 57 | + |
| 58 | +Return the value of 22.<u>857142</u> or `23`. |
| 59 | + |
| 60 | +## Implementation |
| 61 | + |
| 62 | +- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/average.py) |
| 63 | + |
| 64 | +## Video URL |
| 65 | + |
| 66 | +- [Mean on Khan Academy](https://www.khanacademy.org/math/ap-statistics/summarizing-quantitative-data-ap/measuring-center-quantitative/v/mean-median-and-mode) |
| 67 | + |
| 68 | +## Others |
| 69 | + |
| 70 | +- [Mean on Wikipedia](https://en.wikipedia.org/wiki/Mean) |
0 commit comments