Question: Monty Hall Simulation Provided below is some template of code that you can build on to complete the function. As you fill in the code,
Monty Hall Simulation
Provided below is some template of code that you can build on to complete the function. As you fill in the code,
uncomment the lines of code. I have left you some hints along the way. You may approach the problem in a different way if
you would like, but here is how I approached it
Code
monty functionstrat cstay "switch", "random" N
#N is number of iterations
#strat 'stay', 'switch', 'random' is the strategy you use.win #to keep track of number of winsprizesample: size #randomize which door has the good prizeReveal one of the doors you didn't pick which has a bum prizereveal #Insert Code. This line should assign to reveal the door that is neither the prreveal #Insert Code. This line should sample randomly from the two doors that are the no
ifstrat 'switch'select #Insert Code. This line should assign to select the guess.ifstrat 'random'ifselect prize ifstrat 'switch'
# select #Insert Code. This line should assign to select the door that is neither the one
#
# ifstrat 'stay'
# select #Insert Code. This line should assign to select the guess.
#
# ifstrat 'random'ifselect prizepasteUsing the strat, strategy, your win percentage was Print the win percentage of your strategy
#
#montystrat "stay",
#montystrat "switch",
#montystrat "random",
The following uses Daphna's solution to provide the correct answers. You should test your own function to see if you get
similar answers.
Code
mathrm montystrat "stay",
mathrm montystrat "switch",
montystrat "random",
"Using the stay strategy, your win percentage was
"Using the switch strategy, your win percentage was
"Using the random strategy, your win percentage was
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
