题目
在0~100间随机取10000个整数,这些数组成一个列表。计算列表中所有数的平均数和标准差。
代码
import random
def mean(lst):
s = sum(lst)
n = len(lst)
return s/n
def sd(lst):
import math
mean = sum(lst)/len(lst)
bias_mean = [(x - mean)**2 for x in lst]
s2 = sum(bias_mean)/len(bias_mean)
return math.sqrt(s2)
lst = [random.randint(0,100) for i in range(10000)]
ave = mean(lst)
standard_deviation = sd(lst)