The Monty Hall Problem

The Monty Hall problem is a counter-intuitive brain teaser based on probabilities.

This puzzle is named after Monty Hall, the TV presenter of “Let’s Make a Deal”, an American TV show (known as “Deal or No Deal” in the UK) where contenders swap boxes of different values in order to win a prize.

In a similar approach, the aim of the Monty Hall puzzle is to try to win a car by knocking on the right door. The player is presented with three closed doors. Behind one of these doors is a luxurious car. Behind each of the other two doors is a goat!

Here is how the game proceeds:

  • You first pick a door. It could be that you picked the door with the car but you do not know that yet!
  • The game show host examines the other two doors and opens one with a goat. (Note that when both doors are hiding a goat, the presenter picks one of these doors randomly.)
  • You then need to make a decision: You can either stick with your initial guess and open the door to see if you win the car. Alternatively, you can decide to switch your door with the other closed door!

You can give it a go using our interactive game below:

What are the Odds?

When being asked whether to stick to your first guess or change your mind, there are only two closed doors left: One door hiding a goat and one door hiding the car. You could therefore assume that the odds of winning the car are 50-50! This is however a misconception! And if you play the game several times in a row, you will soon realise that you are twice more likely to win the car if you decide to switch your initial guess with the other door!

Not convinced? Try it… And if you want to fully understand the probabilities of this counter-intuitive puzzle you can check this page.

Frequency Analysis

In order to confirm these odds, we would like you to create a Python program that will simulate 100 games in a row, randomly positioning the two goats and the car behind the three doors every time. The program should then automatically and randomly select a door, reveal one door/goat and decide whether to switch doors or not. It should then determine whether the selected door leads to the car or the goat and keep a tally count of wins and losses.

At the end of the 100 attempts, the program should output the statistics as follows:

Python Code

We have only just started the code and thought about the key steps needed to complete this challenge. Your task is to complete the code below to produce a similar output (See statistics displayed above).

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.4 / 5. Vote count: 38

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!