Skip to content

Instantly share code, notes, and snippets.

@rch850
Created July 11, 2019 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rch850/7a63be17a3940425de22343753fc5aff to your computer and use it in GitHub Desktop.
Save rch850/7a63be17a3940425de22343753fc5aff to your computer and use it in GitHub Desktop.
# Simulate Monty Hall Problem
# https://analytics-notty.tech/very-good-explain-montyhall-problem/
import random
def game(change):
doors = [1, 2, 3]
bingo = random.choice(doors)
hand = random.choice(doors)
if change:
return hand != bingo
else:
return hand == bingo
n = 1000
x = 0
for i in range(n):
if game(True): x += 1
print('If you change hand, ', x, 'wins in', n, 'games')
x = 0
for i in range(n):
if game(False): x += 1
print('If you do not change hand, ', x, 'wins in', n, 'games')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment