The Monty Hall Problem

Audience: Beginning programming students

Objectives

  1. Students will learn the value of thinking a problem through before they program
  2. Students will learn that the obvious answer is often wrong

Exercise

The Monty Hall problem is based on the old TV game show Let’s Make a Deal. In that show, the moderator, Monty Hall, would select a member of the audience, and offer them a valuable prize. The prize was behind one of three doors. Behind the other two were joke prizes, like a goat and a can of paint. The member of the audience would select one of the doors (say, door number 2). Monty would then say, “Before I show you what’s behind door number 2, let me show you what’s behind door number 1.” Door number 1 would open, to show the can of paint. Then Monty would ask if the player wanted to change to a different door. The question is, should the player do so?

Write a program to simulate 100,000 iterations of the Monty Hall problem. Use the simulation to demonstrate whether it is to the player’s advantage to change doors.

Discussion questions

  1. Do you think the simulation is accurate, based on the results? Why or why not?
  2. What is the minimum number of lines of code to do the simulation?