Skip to content

Instantly share code, notes, and snippets.

@niyazpk
Created November 14, 2012 16:08
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 niyazpk/4073001 to your computer and use it in GitHub Desktop.
Save niyazpk/4073001 to your computer and use it in GitHub Desktop.
A Tiny program to simulate the Monty Hall problem
from random import randint, choice
p_switch = 0
p_no_switch = 0
for i in range(0, 100000):
choices = ['G'] * 3
choices[randint(0, len(choices) - 1)] = 'C'
# Dude chooses once
my_choice = choice(choices)
if my_choice == 'C':
p_no_switch += 1;
else:
# if you want, you can write code here to remove all the 'G's
# eventually you will see that there is a 'C' left
# and then you increment the counter below.
# if there is no 'C' here, it'd not have entered the "else" case
p_switch += 1;
print p_switch, p_no_switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment