"The host of the show lets the contestant make an initial choice, then opens one of the doors (not the one the contestant has chosen) and then offers the contestant the choice to switch doors.\n",
"The host of the show lets the contestant make an initial choice, then opens one of the doors (not the one the contestant has chosen) and then offers the contestant the choice to switch doors.\n",
In this puzzle, a contestant in a game-show gets to choose between 3 doors.
In this puzzle, a contestant in a game-show gets to choose between 3 doors.
Behind one of the doors, a prize (the "car") is hidden, the other two doors do not win (the "goat").
Behind one of the doors, a prize (the "car") is hidden, the other two doors do not win (the "goat").
The host of the show lets the contestant make an initial choice, then opens one of the doors (not the one the contestant has chosen) and then offers the contestant the choice to switch doors.
The host of the show lets the contestant make an initial choice, then opens one of the doors (not the one the contestant has chosen) and then offers the contestant the choice to switch doors.
Is it beneficial to switch the doors?
Is it beneficial to switch the doors?
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
```python
importrandom
importrandom
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
```python
defmonty_hall_simulation(num_trials=5000):
defmonty_hall_simulation(num_trials=5000):
stay_wins=0
stay_wins=0
switch_wins=0
switch_wins=0
for_inrange(num_trials):
for_inrange(num_trials):
# Randomly place the car behind one of the three doors
# Randomly place the car behind one of the three doors
car_door=random.randint(1,3)
car_door=random.randint(1,3)
# Contestant makes an initial choice randomly
# Contestant makes an initial choice randomly
contestant_choice=random.randint(1,3)
contestant_choice=random.randint(1,3)
# Host opens a door
# Host opens a door
possible_doors=[1,2,3]
possible_doors=[1,2,3]
# Host cannot open the door with the car or the contestant's choice
# Host cannot open the door with the car or the contestant's choice