Python练习
题目:羊车门问题
概率论没学好,理解起来好蛋疼,参考了一下其他人的:
传送门1:link
传送门2:link
import random
car_location=random.randint(1,3)
totle=1000
zhong=0
buzhong=0
for i in range(totle):
first_choice=random.randint(1,3)
if first_choice==car_location:
buzhong+=1
else:
zhong+=1
print("在实验次数{}次,换门的情况下:".format(totle))
print("中奖概率: {:.4f}\n不中概率: {:.4f}".format(buzhong/totle,zhong/totle))