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

Python 3, Monty Door Problem. Include docstrings. Experiment: ·Choose t he prize

ID: 3704584 • Letter: P

Question

Python 3, Monty Door Problem. Include docstrings.

Experiment: ·Choose t he prize door randomly and uniformly over 11,231. . Choose your door randomly and uniformly over [1,2,3 Monty Hall chooses the door that is not the prize door and not your door You may or may not switch to the remaining door With the never-switch policy, you never switch With the always-switch policy, you always switch. With the randoswitch policy, you flip a fair con to decide if you swiich. The experiment yields an answer: did you win the prize?

Explanation / Answer

1.

import numpy
prizesdoor=[1,2,3]
contestant=[1,2,3]

def montyDoor(prize,contestant):
  prize_door = numpy.random.randint(0, len(prizesdoor)-1)
if(prizesdoor[prize_door]!=price && prizesdoor[prize_door]!=contestant ):
  return prizesdoor[prize_door]

2.

def otherDoor(contestant,monty):
prize_door = numpy.random.randint(0, len(prizesdoor)-1)
if(prizesdoor[prize_door]!=contestant && prizesdoor[prize_door]!=monty):

return prizesdoor[prize_door]
else:
#switch to other door.
other_door=numpy.random.choice([i for i in prizesdoor if i not in [monty, contestant]])
return other_door

3.

def trialMonty(style,nExp=1000):

wins = 0.0
losses = 0.0
  
for i in range(nExp):
n = r.randrange(0,3)
  
choice = doors[style]
if style == 0:
#print "You chose door 1."
#print "Monty opens door 2.
#print "You swapped to door 3."
wins += 1
#print "You won a " + doors[2] + " "
elif style == 1:
#print "You chose door 2."
#print "Monty opens door 1.
#print "You swapped to door 3."
wins += 1
#print "You won a " + doors[2] + " "
elif style == 2:
#print "You chose door 3."
#print "Monty opens door 2.
#print "You swapped to door 1."
losses += 1
#print "You won a " + doors[0] + " "
else:
print "You screwed up"
percentage = (wins/iterations) * 100
print "You won " + str(percentage) + "% of the time"