Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sim(n):
- # runs a single trial.
- # assume car is in door 1.
- # returns True if switching leads to car, False otherwise.
- if random.randint(1, n) == 1:
- return False
- # host picks a door, so there are n - 2 remaining doors.
- return random.randint(1, n - 2) == 1
- N = 4
- TRIALS = 100000
- successes = 0
- for i in xrange(TRIALS):
- if sim(N):
- successes += 1
- print float(successes) / TRIALS
Advertisement
Add Comment
Please, Sign In to add comment