The Monte Hall Problem

Instructions

  • Read input number into variable.
  • Define a variable to count the number of wins and initialize it to 0.
  • Use a for loop to do the experiment the requested number of times:
    • Host hides prize behind a random door. Define a variable for this and set it to a random number from 1 to 3.
    • Contestant selects a random door. Define a variable for this and set it to a random number from 1 to 3.
    • Host reveals an unchosen door not containing prize. A reasonable way to do this is to define a variable and set it to a random number from 1 to 3, then use a while loop to reset it as long as it equals the prize door or the chosen door.
    • Contestant switches to another door. This will be the door not chosen and not revealed. (A quick computation would be 1 + 2 + 3 – chosen door – revealed door.)
    • If the switched-to door is also the prize door, add 1 to the wins count.
  • Show the win percentage (wins / trials).