In: Computer Science
Thank You
Algorithm: The mean of a list can be calculated by dividing the sum of of all elements of the list by the count of elements in the list.
I have also written the code for standard deviation. Have a look at the below code. I have put comments wherever required for better understanding.
import math
def mean(list):
# variable to store total sum
total_sum = 0
# variablle to store total count
total_count = len(list)
# calculate the sum
for i in list:
total_sum+=i
# find the mean
mean = total_sum/total_count
# return mean
return mean
def standard_deviation(list):
total_count = len(list)
mean_value = mean(list)
total = 0
for i in list:
total+=pow(i-mean_value,2)
standard_deviation = math.sqrt(total/total_count)
return standard_deviation
Happy Learning!