首页 > 代码库 > 羊车门问题python模拟
羊车门问题python模拟
羊车门问题
羊车门问题描述:有3扇关闭的门,一扇门后停着汽车,另外两扇门后是山羊,主持人知道每扇门后是什么。参赛者首先选择一扇门。在开启它之前,主持人会从另外两扇门中打开一扇门,露出门后的山羊。此时,允许参赛者更换自己的选择。请问,参赛者更换选择后,能否增加猜中汽车的机会?通过设计并编写程序验证,并给出自己的解释。答案要求以如下方式给出。(The sheep door has 3 closed door, a door parked car, another two door is a goat, the host knows every door. What is the first choice of the contestants in the open door. Before it, the moderator will open a door from the other two doors, exposes the goat after. At this time, allow the participants change their choice. Please choose the contestants after replacement, can increase the chance of guessing car? Please through design and program verification, and gives his own interpretation. )
1、我认为会增加选中汽车的机会。
原因如下:
(1)不换选择:选对的概率为1/3 (2)换选择:概率为在更换选择前选择了羊,更换后选择了车。概率为2/3*1
2、程序源代码如下):
from random import*
TIMES = 10000
my_first_choice_n=0#初始化不改选择的次数
my_change_choice_n=0#初始化更改选择的次数
for i in range(TIMES):
a="羊1","羊2","车"
car_inDoor=choice(a)
my_guess=choice(a)
if car_inDoor==my_guess:
my_first_choice_n+=1
else:
my_change_choice_n+=1
print("不改选择:{}".format(my_first_choice_n/TIMES))
print("更改选择:{}".format(my_change_choice_n/TIMES))
3.运行的验证结果如下:
羊车门问题python模拟