The Monty Hall Puzzle

You’ve all heard this puzzle. Remember the game show “Let’s Make a Deal”, there are three closed doors and behind one is a prize. The contestant picks a door, then the host – Monty Hall – opens a different door. The prize is not behind the door Monty opens. Now the contestant has an option to stick to the original choice or switch. Should you switch or not?

Turns out the answer is that you should always switch. In fact the probability of winning the prize is 2/3 if you switch.

Many people have hard time understanding why this is so. Once I explained the solution to a friend and he still did not believe me. So I wrote the following program to simulate 10,000 games and calculate the probability. Here is the code in Python:

from random import randint
def pick (doors):
        result = randint (1,3)
        while result in doors:
                result = randint (1,3)
        return result
total_wins = 0
for i in range (1,10000):
        prize_door = randint (1,3)
        guess_door = randint (1,3)
        monty_door = pick ([prize_door, guess_door])
        switched_door = pick ([guess_door, monty_door])
        if (switched_door == prize_door):
                total_wins += 1
print “Total games: %d Total wins: % d ” % (i, total_wins)
When I run this program here are several results:
Total games: 9999 Total wins:  6700
Total games: 9999 Total wins:  6675
Total games: 9999 Total wins:  6619
So, as you can see the probability of winning is about 2/3rds….
I rest my case. 🙂