本文共 498 字,大约阅读时间需要 1 分钟。
import random"""波利亚过程一只瓮里面装着一个白球和一个黑球。每一周期,都随机抽取出一个球并将这个球与和它颜色相同的另一个球一起放回到瓮中。抽取出来的球的颜色表示结果。"""box = ["white", "black"]# for i in range(1000): # ball = random.choice(box)# if i < 10:# if ball == "white":# white_sum += 1# box.append(ball)# print(white_sum)# print(box.count("white") / len(box))# for i in range(1000):# ball = random.choice(box)# if ball == "white":# box.append("black")# box.append("white")# print(box.count("white") / len(box))
转载地址:http://vrkbz.baihongyu.com/