Created
November 14, 2012 16:08
-
-
Save niyazpk/4073001 to your computer and use it in GitHub Desktop.
A Tiny program to simulate the Monty Hall problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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