from statistics import stdev
import numpy as np

################# using pure python #########################
x = [8.0, 1, 2.5, 4, 28.0]

n = len(x)
mean_ = sum(x) / n
var_ = sum((item - mean_)**2 for item in x) / (n - 1)
std = var_ ** 0.5
print("standard deviation using pure python: ",std)


############### using statistics ############################

sample1 = (1, 2, 5, 4, 8, 9, 12)
print("The Standard Deviation of Sample1 is % s" % (stdev(sample1)))

sample2 = (-2, -4, -3, -1, -5, -6)
print("The Standard Deviation of Sample2 is % s" % (stdev(sample2)))
 
sample3 = (-9, -1, 0, 2, 1, 3, 4, 19)
print("The Standard Deviation of Sample3 is % s" % (stdev(sample3)))
 
sample4 = (1.23, 1.45, 2.1, 2.2, 1.9)
print("The Standard Deviation of Sample4 is % s" % (stdev(sample4)))

################# using np.std ###########################
x = [8.0, 1, 2.5, 4, 28.0]
y = np.array(x)
std = np.std(y, ddof=1)
print("The Standard Deviation using np.std(): ",std)