Created
April 18, 2019 18:56
-
-
Save thomasnield/95443be4d5255929a0d716933df29de7 to your computer and use it in GitHub Desktop.
Monty Hall 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 random_door(): | |
| return randint(1, 3) | |
| trial_count = 10000 | |
| stay_wins = 0 | |
| switch_wins = 0 | |
| for i in range(0, trial_count): | |
| prize_door = random_door() | |
| selected_door = random_door() | |
| opened_door = list(d for d in range(1, 4) if d != selected_door and d != prize_door)[0] | |
| switch_door = list(d for d in range(1, 4) if d != selected_door and d != opened_door)[0] | |
| if selected_door == prize_door: | |
| stay_wins += 1 | |
| if switch_door == prize_door: | |
| switch_wins += 1 | |
| print("STAY WIN RATE: {}, SWITCH WIN RATE: {}".format(float(stay_wins)/float(trial_count), float(switch_wins)/float(trial_count))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment