Created
August 29, 2013 02:09
-
-
Save actsasgeek/6373559 to your computer and use it in GitHub Desktop.
Monty Hall problem in Python.
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 | |
| def evaluate_a_monty_hall_scenario(switch=False): | |
| options = set([1, 2, 3]) | |
| car = randint( 1, 3) | |
| pick = randint( 1, 3) | |
| opened = list( options.difference( set([car])).difference( set([pick])))[0] | |
| closed = list( options.difference( set([pick])).difference( set([opened])))[0] | |
| if switch: | |
| pick = closed | |
| return car == pick | |
| def evaluate_monty_hall_problem( switch=False): | |
| trials = 10000 | |
| count = 0 | |
| for i in range( 0, trials): | |
| result = evaluate_a_monty_hall_scenario( switch) | |
| if result: | |
| count += 1 | |
| return float( count) / trials | |
| evaluate_monty_hall_problem(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment