Created
October 2, 2021 14:23
-
-
Save ycytai/92d84a4a98f3c20d1f01669192b793c5 to your computer and use it in GitHub Desktop.
This file contains 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 | |
doors = ['Goat', 'Car', 'Goat'] | |
n = 1000 | |
win = 0 | |
lose = 0 | |
for _ in range(n): | |
#-------------------------# | |
# shuffle and random pick # | |
#-------------------------# | |
random.shuffle(doors) | |
first_choice = random.randrange(3) | |
#--------------------------------# | |
# open a door with a goat behind # | |
#--------------------------------# | |
for idx, gift in enumerate(doors): | |
if idx != first_choice and gift == 'Goat': | |
open_door = idx | |
#----------------------------# | |
# change the original choice # | |
#----------------------------# | |
choices = [0, 1, 2] | |
choices.remove(first_choice) | |
choices.remove(open_door) | |
second_choice = choices[0] | |
#--------# | |
# result # | |
#--------# | |
if doors[second_choice] == 'Car': | |
win += 1 | |
else: | |
lose += 1 | |
print(f'Win:{win}, Lose:{lose}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment