Standard Deviation

Probability and StatisticsEasy+10 XP+10

Standard Deviation

Variance has an awkward flaw: because every distance got squared, it comes out in squared units. Measure heights in centimetres and the variance is in square centimetres, which means nothing to anybody.

Standard deviation undoes that. Take the square root of the variance and you're back in the original units — a spread you can actually compare to the data.

Task: write standard_deviation(values) returning the square root of the sample variance, rounded to 4 decimal places.

  • Use the sample variance on the way there: divide the squared distances by n - 1, not n.
  • values always holds at least two numbers.
  • Round only at the end. Rounding the variance first and then taking its square root will drift off in the last decimal place.

Read the result as "a typical distance from the mean". If the mean height is 170 cm and the standard deviation is 6 cm, most people in the list sit within about 6 cm of 170.

Examples

values = [2, 4, 4, 4, 5, 5, 7, 9]
returns 2.1381
values = [1, 2]
returns 0.7071

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run