Sometimes when dealing with probabilities, things don't always work out the way you might expect. My favorite example of this is the Monty Hall problem. The name comes from the game show Let's Make a Deal, which was hosted by Monty Hall when it debuted in the 1960s. It’s still running today (with a different host), and the gameplay remains the same: A contestant chooses among three closed doors—behind one of which is a prize.
Let's say these doors are labeled 1, 2, and 3. The player picks a door—let’s go with door number 2. After that, Monty opens one of the other doors to show that it does not have the prize. (Suppose it's door number 1.) Now the contestant can either stick with the original choice (door 2) or switch to the other unopened door (door 3). So what would you do? Stick to your guns and stay with door 2, or waffle and go with door 3? (To make this even more stressful, imagine that the audience is yelling their opinions at you—plus you're on television, which always adds some tension.)
It turns out that you are more likely to win the prize if you switch your choice. Yes, I agree— this doesn't seem to make much sense. I mean, when you first picked a door, you didn't know which one was hiding the prize. And after Monty reveals a losing door, you still don't know which one is the winner. Now you are down to two doors instead of three. It doesn't seem like choosing one random door over another would improve your odds—but indeed it does. You start with a 1 out of 3 chance of winning, but if you switch your answer, your chance of winning will now be 2 out of 3.
That seems bizarre, so I want to test this myself. OK, I don't want to actually test it. Sure, I could get a friend to make some doors, hide a prize behind one, and let me guess. But unless we do this a whole bunch of times, it will be hard to see if it's really better to switch doors—and nobody has time for this.
How about the next best thing: modeling the problem in Python! It seems like you should be able to solve a problem named after a famous Monty with a programming language named after another famous Monty—in this case, the BBC series Monty Python's Flying Circus.
I'm going to walk you through the basic steps of modeling this with Python. If we can get this to work for one trial, we can just as easily do it for 1,000 or even 10,000 trials.
We need to do two things: model the case without switching doors, and then again using the switching option.
This option is pretty easy to model. We can use a random number generator to pick which door has the prize and then pick another random number for the contestant’s choice. If the choice and the prize are the same, it's a win.
For this model, I’m going to use a version of Python called Web VPython that is perfect for physics because it can be used to make 3D objects and move them around. Plus, it runs online so you don't have to install anything. (But I should point out that it handles some things in a different manner than regular Python.)