Write a program that defines functions (mean and deviation), that computes mean and standard deviation of given numbers. The formula for the mean and standard deviation of n numbers is given as:



Code

import math

def mean(numbers):
return sum(numbers) / float(len(numbers))

def std_dev(numbers):
avg = mean(numbers)
variance = sum([pow(x-avg,2) for x in numbers]) / float(len(numbers)-1)
return math.sqrt(variance)

if __name__ == '__main__':
n = int(input("Enter the number of elements: "))
numbers = []
for i in range(n):
numbers.append(float(input("Enter the element: ")))
print("Mean: ", mean(numbers))
print("Standard Deviation: ", std_dev(numbers))

Output