Q:

Python program to find standard deviation

belongs to collection: Python basic programs

0

Python program to find standard deviation

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

So here is the function code:

def stdv(X):
    mean = sum(X)/len(X)
    tot = 0.0
    for x in X:
        tot = tot + (x - mean)**2
    return (tot/len(X))**0.5

# main code
#  a simple data-set 
sample = [1, 2, 3, 4, 5] 
print("Standard Deviation of the sample is: ", stdv(sample))

sample = [1, 2, 3, -4, -5] 
print("Standard Deviation of the sample is: ", stdv(sample))

sample = [10, -20, 30, -40, 50] 
print("Standard Deviation of the sample is: ", stdv(sample))

Output:

Standard Deviation of the sample is:  1.4142135623730951 
Standard Deviation of the sample is:  3.2619012860600183 
Standard Deviation of the sample is:  32.61901286060018 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program to find the variance... >>
<< Python program for Tower of Hanoi...