05.编程理解小数和大数定律
1import random 2import matplotlib.pyplot as plt 34
5# 掷硬币,头0,花1
6def toss():
7return random.randint(0, 1)
8
9
10if__name__ == "__main__":
11
12 indices = []
13 freq = []
14for toss_num in range(10, 10001, 10):
15
16 heads = 0
17for _ in range(toss_num):
18if toss() == 0:
19 heads += 1
20 freq.append(heads / toss_num)
21 indices.append(toss_num)
22
23 plt.plot(indices, freq)
24 plt.show()
以上是 05.编程理解小数和大数定律 的全部内容, 来源链接: utcz.com/a/77963.html