After I’d covered the Monty Hall Problem in the last blog-post, I wrote an experiment in python, which shows that when the number of doors increases but the rules of the game stay the say, our probability of winning given that we switched converges to 1. The probability of winning given we stayed converges to 0.

The experiment shows what our intuition probably already told us. The higher the number of doors the higher the probability that we choose a “goat door” first and when Monty Hall then opens all other Goat doors, the only one left is the “car door”. Our probability of winning when we switch therefore increases when the number of doors increases.

Here is the source code for my experiment.

import matplotlib.pyplot as plt
import numpy as np
import random
stay_graph = [[], []]
switch_graph = [[], []]
for doors in range(3,101):
stay = []
switch = []
for i in range(10000):
prizes = [0 for i in range(doors)]
prize_behind = random.randint(0, doors-1)
prizes[prize_behind] = 1
# I alway choose door 1
if prizes[0]==1:
stay.append(1)
switch.append(0)
else:
stay.append(0)
switch.append(1)
#calculate means
stay_mean = np.mean(stay)
switch_mean = np.mean(switch)
#print('Stay: {} \nSwitch: {}'.format(stay_mean, switch_mean))
stay_graph[0].append(doors)
stay_graph[1].append(stay_mean)
switch_graph[0].append(doors)
switch_graph[1].append(switch_mean)
plt.plot(stay_graph[0], stay_graph[1], color='blue', label='Stay')
plt.plot(switch_graph[0], switch_graph[1], color='red', label='Switch')
plt.xlabel('Number of Doors')
plt.ylabel('Probability of Winning')
plt.title('Monty Hall')
plt.legend()
plt.show()

The code produces the following graphs:

### Like this:

Like Loading...

*Related*