### [2021-05-10] Challenge #389 [Easy] The Monty Hall problem

Here is my take on this in Python, including the bonus contestants:

``````import random
``````

def run_game(player,times_to_play): times_played = 0 win_count = 0 if player == "Gina": mimic_player = "Alice" else: mimic_player = "N"

``````while times_played < times_to_play:
#Step 1 - Monty selects prize door
Monty_choice = random.randint(1,3)

#Step 2 - Player's initial door selection
if player == "Alice" or player == "Bob" or player == "Frank" or player == "Gina":
Player_choice = 1
if player == "Carol" or player == "Dave" or player == "Erin":
Player_choice = random.randint(1,3)

#Step #3 - Monty selects door to open
Monty_open_selections = []
for i in range(1,4):
if i == Monty_choice or i == Player_choice:
continue
else:
Monty_open_selections.append(i)

Monty_opened = random.choice(Monty_open_selections)

#Step 4 - Player's switch decision
Player_choice_selections = []
if player == "Alice" or player == "Dave" or mimic_player == "Alice":
pass
if player == "Bob" or player == "Erin" or mimic_player == "Bob":
for i in range(1,4):
if i == Player_choice or i == Monty_opened:
continue
else:
Player_choice = i
break
if player == "Carol":
for i in range(1,4):
if i == Monty_opened:
continue
else:
Player_choice_selections.append(i)
Player_choice = random.choice(Player_choice_selections)
if player == "Frank":
if Monty_opened != 2:
Player_choice = 2
else:
pass

#Step 5 - Win/Loss evaluation
if Player_choice == Monty_choice:
win_count += 1
else:
if player == "Gina":
mimic_player = "Bob" if mimic_player == "Alice" else "Alice"
times_played += 1

return win_count
``````

n = 1000 Alice_wins_pct = run_game("Alice",n)/n Bob_wins_pct = run_game("Bob",n)/n Carol_wins_pct = run_game("Carol",n)/n Dave_wins_pct = run_game("Dave",n)/n Erin_wins_pct = run_game("Erin",n)/n Frank_wins_pct = run_game("Frank",n)/n Gina_wins_pct = run_game("Gina",n)/n

print(f"Alice win percentage: {Alice_wins_pct:.2%}") print(f"Bob win percentage: {Bob_wins_pct:.2%}") print(f"Carol win percentage: {Carol_wins_pct:.2%}") print(f"Dave win percentage: {Dave_wins_pct:.2%}") print(f"Erin win percentage: {Erin_wins_pct:.2%}") print(f"Frank win percentage: {Frank_wins_pct:.2%}") print(f"Gina win percentage: {Gina_wins_pct:.2%}")

Sample output:

``````Alice win percentage: 31.20%
``````

Bob win percentage: 66.40% Carol win percentage: 49.40% Dave win percentage: 34.80% Erin win percentage: 66.60% Frank win percentage: 48.90% Gina win percentage: 55.10%