Python Monty Hall Problem Simulation

The Monty Hall Problem is a very (to me at least) counter-intuitive probability mind-experiment which contorts my brain and fascinates me at the same time, I have been mulling it over the last few weeks and wanted to write a little simulator to see if the numbers come out as predicted (if not expected, and indeed they do!). I can just about understand the probabilistic arguments, but I still find it very confusing, as soon as I think that I grok it – my ‘understanding’ disappears into the night! I am used to being this bamboozled when reading about quantum mechanics or something, but I find it fascinating that such an apparently simple problem can be so deceptively deep!


There are 3 doors, behind one lies a car, while behind the other two are goats. A player chooses a door at random. Monty opens one of the other doors to show that there is a goat behind it. Monty then asks the player if they would like to stick with their original choice of door or switch to the other un-opened door.

If the player sticks with their door then their chance of winning the car should be 1/3. If the player switches door then their chances of winning the car increases to 2/3!!!

If you are having problems understanding the outcome, I find it helps to imagine that there are a million doors rather than 3. After you choose your door (1/1,000,000 chance of hiding the car) Monty opens up 999,998 doors that hide goats to leave one door still closed. Now which door do you think is most likely to hide the car? The one you choose, or the one that Monty avoided opening while he opened all 999,998 other doors?! It seems obvious to me that the other door that Monty left un-opened has a massively higher chance of hiding the car than your original choice! As N reduces to 3 this ‘obviousness’ reduces greatly however! This simulator allows you to experiment with more then 3 doors for this reason.

For more info:

This program is an experimental simulator to see what numbers we get when the player decides to stick or switch. It can be found on GitHub.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *