Better Programming

Advice for programmers.

Follow publication

Member-only story

Solving the Monty Hall Problem With Python

Yong Cui
Better Programming
Published in
6 min readJul 8, 2021

--

Dice stacked on top of one another
Photo by Terry Vlisidis on Unsplash

The Monty Hall Problem

The Monty Hall problem is one of the most famous probability puzzles. It was named after Monty Hall, the host for the American TV game show which involved the following problem. The description below is the most typical setup of the game, and it’s just for explanations — the actual awards may be different.

Suppose that you can choose to open a door, behind which there will be an award. There are three doors in total: behind one is a car and behind the others two are goats. After you pick a door, from the remaining two doors, the host will open a door behind which there is a goat for you. At this moment, you’ll be asked whether you want to switch your initial selection to the remaining closed door. Suppose your goal is to maximize the chance of winning the car.

The Puzzling Part and a Simple Solution

At this point, you’re left with two doors: one has the car and the other has a goat. So it appears that it doesn’t matter, you switch your selection or not because the chance is 50% when you pick one from two. However, the truth is that it’s advantageous for…

--

--

Yong Cui
Yong Cui

Written by Yong Cui

Work at the nexus of biomedicine, data science & mobile dev. Author of Python How-to by Manning (https://www.manning.com/books/python-how-to).

Write a response