Question: (Python) In the 1970s, there was a popular television game show called Let's Make a Deal. At the end of the show, a contestant played
(Python) In the 1970s, there was a popular television game show called "Let's Make a Deal". At the end of the show, a contestant played a game, attempting to win a prize. The game show host, Monty Hall, would show the contestant 3 closed doors. Behind one of the doors was the prize, and the contestant was asked to guess which door it was. Once the contestant made a guess, Monty Hall would open one of the otherdoors, showing that the prize was not behind it. The contestant was then given the opportunity of either changing his or her guess, or sticking to his or her original guess. Monty Hall would then reveal what was behind the other two doors.
The common belief was that there was no advantage in changing one's guess. The reasoning went as follows: after one of the doors was eliminated, the prize must be behind one of the two remaining doors. Then the probability of the prize being behind the door the contestant originally guessed was 0.5. The probability of the prize being behind the other door was also 0.5. Since there was an equal chance of the prize being behind either door, it didn't matter whether you switched or not.
There is a popular column in Parade magazine called "Ask Marilyn". Marilyn vos Savant is said to have the highest measured IQ according to the Guinness Book of World Records, and she would answer questions from readers in her column. In 1990, a reader wrote to her asking her what the best strategy would be to play this game. Her advice was: no matter what the initial guess was, always switch. A large number of readers, including college math professors, wrote her and berated her for her "incorrect" response. However, it is easy to show that she was correct!
In this programming assignment, you are going to simulate the game and demonstrate that Marilyn vos Savant did indeed give sensible advice. The following describes the algorithm you should follow:
Prompt the user to enter the number of trials to run.
Create a variable to keep track of the number of times the contestant wins by switching.
Generate a random number between 1 and 3, inclusive, that will denote the door that conceals the prize. Do this by importing the random package and calling random.randint(1,3). (If you need additional help understanding how to use this function, refer to section 4.3 in your textbook.)
Generate another random number between 1 and 3, inclusive, that will denote the guess the contestant makes.
From those two numbers, find a number that is neither the door concealing the prize nor the contestant's guess. This is the door that is opened by Monty Hall; let's call it view.
The contestant now switches by making a newGuess that is neither the original guess nor the view.
Compare the value of newGuess against the value of prize. If they are the same, the contestant won by switching. If not, the contestant lost by switching.
If the contestant won by switching, increment the variable that was keeping count of wins.
Run this simulation for the number of times the user had specified at the start.
To obtain the probability for winning if you switch, divide the number of times the contestant wins by switching by the total number of games played.
To obtain the probability of winning by not switching, subtract the above number from one.
Input and Output
The only input for your program is the number of of trials you want to run. Your output must look exactly like the following (although the value of the numbers are likely to be different):
How many trials do you want to run? 10 Prize Guess View New Guess 2 3 1 2 3 2 1 3 2 1 3 2 2 2 1 3 3 1 2 3 2 2 1 3 2 1 3 2 1 3 2 1 3 3 1 2 3 2 1 3 Probability of winning if you switch = 0.7 Probability of winning if you do not switch = 0.3
Remember that since we're using random numbers, your results will vary each time you run your program. However, keep in mind that the more trials you run, the more accurate your results will become. Try running your program for larger numbers of trials and see what your result is.
Additional Requirements:
Your program must include a function called roll(n) that returns a random number between 1 and n, inclusive. You will call this function whenever you need to randomly choose a door.
Your program must include a function called runOneTrial(). This function will implement steps 3 through 7 in the algorithm described above. It will return the string "win" to the calling program if switching doors resulted in a win, or "lose" if it doesn't.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
