# Standard Deviation Algorithm

In statistics, given a set list of numbers, the standard deviation is a measure of the amount of variation or dispersion within the set.

A low standard deviation indicates that the values tend to be close to the mean value of the set.
A high standard deviation indicates that the values are spread out over a wider range.

The formula to calculate the standard deviation for a given set of numbers is as follows:

Where x represents the mean value of the set and n represents the number of values in the set.

Your task is to design an algorithm for a function called standardDeviation() that takes one parameter: a list of integer values. The list can be of any length. Your function will calculate and return the standard deviation for this given list.

#### Python Code

We have started the code for you by creating a function called inputList() that lets the user input any list of numbers, one number at a time. Your task is now to add the code for the standardDeviation() function.

#### Test Plan

 Test # Input Values Expected Output Actual Output #1 7,14,9,21,32,15 8.3199893162325 #2 23,101,52,48,107 32.480147782915 #3 10,40 15
[pms-restrict display_to=”not_logged_in” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ display_to=”not_subscribed” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

#### Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

#### Python Code

```#Standard Deviation Algorithm - 101computing.net/standard-deviation-algorithm

def inputList():
list = []
userInput = input("Enter a number to add to your list or 'x' to exit.")
while userInput!="x":
list.append(float(userInput))
userInput = input("Enter a number to add to your list or 'x' to exit.")
return list

def mean(list):
mean = 0
for x in list:
mean = mean + x

if len(list) > 1:
mean = mean / len(list)

return mean

def standardDeviation(list):
n = len(list)
if n<=1:
return 0
else:
sum = 0
meanValue = mean(list)
for x in list:
sum = sum + (x - meanValue) ** 2

s = (sum/n)**0.5
return s

list = inputList()

print("The Standard Deviation is:")
print(standardDeviation(list))```
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 14

No votes so far! Be the first to rate this post.

As you found this challenge interesting...