Skip to content

Instantly share code, notes, and snippets.

Created February 10, 2012 21:36
Show Gist options
  • Save anonymous/1793113 to your computer and use it in GitHub Desktop.
Save anonymous/1793113 to your computer and use it in GitHub Desktop.
Embedly problem 2 in python
def calcSD(arrVals):
numVals = len(arrVals)
print "%d values" % numVals
total = 0
for val in arrVals:
total += val
mean = total / numVals
sqDiffs = 0
for val in arrVals:
sqDiffs = sqDiffs + (val - mean)**2
SD = (sqDiffs / numVals)**0.5
return SD
vals = [4, 5, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 5, 5, 4, 6, 4]
print calcSD(vals)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment