Get startedGet started for free

Standard deviation by hand

In the video, we talked about measures of variability, and discussed standard deviation as the measure that is used most commonly. It's pretty important that you have a grasp on this concept, as interviewers will likely hit on it early on in the process through a coding assignment or something more conceptual.

Here, you'll simulate this experience by computing standard deviation by hand, meaning that you won't use any existing functions like std() to get your results.

This exercise is part of the course

Practicing Statistics Interview Questions in Python

View Course

Exercise instructions

  • Without using the mean() function, compute the mean of our nums list defined for you.
  • Use the computed variance value along with the math.sqrt() function to get the standard deviation; print your result.
  • Check your work by printing the actual standard deviation with the np.std() function mentioned earlier.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create a sample list
import math
nums = [1, 2, 3, 4, 5]

# Compute the mean of the list
mean = ____

# Compute the variance and print the std of the list
variance = sum(pow(x - mean, 2) for x in nums) / len(nums)
std = ____
print(____)

# Compute and print the actual result from numpy
real_std = np.array(____).std()
print(____)
Edit and Run Code