Created
April 19, 2014 08:26
-
-
Save alenbasic/11077884 to your computer and use it in GitHub Desktop.
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
import random | |
right = 0.0 | |
wrong = 0.0 | |
x = 100000 | |
for i in range(x): | |
items = ['goat','prize', 'goat'] | |
random.shuffle(items) | |
choice = random.randrange(0,3) | |
choice_name = items[choice] | |
for j in range(3): | |
if j != choice and items[j] == 'goat': | |
del items[j] | |
break | |
choice = items.index(choice_name) | |
if choice == 1: | |
choice = 0 | |
else: | |
choice = 1 | |
if items[choice] == 'prize': | |
right += 1 | |
else: | |
wrong += 1 | |
print 'You changed your choice and got the prize %.2f%% of the time.' % (right / x * 100) | |
print 'You changed your choice and lost the prize %.2f%% of the time.' % (wrong / x * 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment