Question: **in Python** In this programming assignment, you are going to simulate the game and demonstrate that Marilyn vos Savant did indeed give sensible advice. The
**in Python**
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 callingrandom.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 theguess 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: This is the most important part, I know how to write the program but i dont know how to write it using the functions below!
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
