Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python program to simulate the following variant of the Monty Hall probl

ID: 3730741 • Letter: W

Question

Write a Python program to simulate the following variant of the Monty Hall problem Suppose that, in the beginning, the host does not know where the prize is located After contestant picks a door, the host opens another door uniformly at random (between the two other doors). There are two situations .Aborted game: if the host happens to open a door with the prize, this game does not count and everything will be reshuffled. A new game will start after the reshuffling Completed game: otherwise the game continues as usual. The host asks whether the contestant wants to change the door he/she picked. Now for the contestant, will changing-the-door increase his/her odd to win? Write a Python program to simulate the contestant's winning odd (by running many games Requirement: define a function with name "simulate-gameQ4 ### Solution to Question 4 def simulate game. Q40 Your codes Your program should return the odds of winning for both strategies (changing door and not-changing door) over 10000 completed games. You should use functions from the Python "random module in this question

Explanation / Answer

import random

DOORS = [1,2,3]

def hallpicker(strategy):
prize = random.choice(DOORS)
firstchoice = random.choice(DOORS)
if strategy == 'stay':
return firstchoice == prize
elif strategy == 'switch':
hostchoice = random.choice([x for x in DOORS if x != firstchoice and x != prize])
secondchoice = [x for x in DOORS if x != firstchoice and x != hostchoice]
assert len(secondchoice) == 1
return secondchoice[0] == prize
else:
raise ValueError

def counter(strategy, n=10000):
return sum(hallpicker(strategy) for i in xrange(n))/float(n)

if __name__ == "__main__":
print "stay:", counter('stay')
print "switch:", counter('switch')

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote