Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
stay_value 0.377298
switch_value 0.500682
dtype: float64
import pandas as pd
import numpy as np
import random
def create_stage():
# Returns a list of 3 "doors", with either 'prize' or 'goat' as specified in puzzle
num_goats = np.random.randint(0, 4)
# print(num_goats)
doors = []
while num_goats > 0:
num_goats -= 1
while len(doors) < 3:
return doors
if __name__ == '__main__':
results = []
for i in range(1, 100000):
doors = create_stage()
# Contestant always chooses door #1 (or rather door 0)
contestant_chosen = doors.pop()
# print(contestant_chosen)
# If monty is able, he will open a door with a goat (remove from the list of remaining doors)
if 'goat' in doors:
# print(doors)
# print(len(doors))
results.append({'contestant': contestant_chosen, 'switch': doors[0]})
# save the contestants door and the door if you were to switch
# else:
# print('monty cant open another door...')
results_df = pd.DataFrame(results)
results_df['stay_value'] = results_df['contestant'] == 'prize'
results_df['switch_value'] = results_df['switch'] == 'prize'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.