<jupyter_start><jupyter_text>Monty Hall Problem _____ The Monty Hall problem is named for its similarity to the Let's Make a Deal television game show hosted by Monty Hall. The problem is stated as follows. Assume that a room is equipped with three doors. Behind two are goats, and behind the third is a shiny new car. You are asked to pick a door, and will win whatever is behind it. Let's say you pick door 1. Before the door is opened, however, someone who knows what's behind the doors (Monty Hall) opens one of the other two doors, revealing a goat, and asks you if you wish to change your selection to the third door (i.e., the door which neither you picked nor he opened). The Monty Hall problem is deciding whether you do.The correct answer is that you do want to switch. If you do not switch, you have the expected 1/3 chance of winning the car, since no matter whether you initially picked the correct door, Monty will show you a door with a goat. But after Monty has eliminated one of the doors for you, you obviously do not improve your chances of winning to better than 1/3 by sticking with your original choice. If you now switch doors, however, there is a 2/3 chance you will win the car (counterintuitive though it seems).Now let us check the chance using python code.<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Goats = np.array(['Goat: 1', 'Goat: 2'])
Goats
def get_other_goat(Goat):
    
    if Goat == 'Goat: 1':
        return 'Goat: 2'
    elif Goat == 'Goat: 2':
        return 'Goat: 1'
shift_1 = get_other_goat('Goat: 1')
shift_2 = get_other_goat('Goat: 2')
print('If door corresponds to Goat: 1 is selected then open - ',shift_1 )
print('If door corresponds to Goat: 2 is selected then open - ',shift_2 )
Hidden_behind_doors = np.array(['Car', 'Goat: 1', 'Goat: 2'])
Hidden_behind_doors
def monty_hall_game():
    
    contestant_guess = np.random.choice(Hidden_behind_doors)
    
    if contestant_guess == 'Goat: 1':
        return [contestant_guess, 'Goat: 2', 'Car']
    
    if contestant_guess == 'Goat: 2':
        return [contestant_guess, 'Goat: 1', 'Car']
    
    if contestant_guess == 'Car':
        revealed = np.random.choice(Goats)
        return [contestant_guess, revealed, get_other_goat(revealed)]
monty_hall_game()
play = []

for i in np.arange(10000):
    
    play.append(monty_hall_game())
    
Games = pd.DataFrame(play, columns = ['Guess', 'Revealed', 'Remaining'])
Games
Guess_count = Games.pivot_table(index = ['Guess'], aggfunc ='size')
Guess_count
Remaining_count = pd.pivot_table(Games, index = ['Remaining'], aggfunc ='size')
Remaining_count
Data = pd.DataFrame([['Car', Guess_count[0],  Remaining_count[0]], ['Goat: 1', Guess_count[1], Remaining_count[1]], ['Goat: 2', Guess_count[2], Remaining_count[2]]], columns=['Item', 'Original Door', 'Remaining Door']) 
Data
ax = Data.plot.barh(0)
ax.set_xlabel('Count')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10204081632653061, 'fraction_numerical': 0.013945578231292517, 'mean_word_length': 4.299099099099099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '341099', 'license': 'Apache-2.0', 'n_tokens_mistral': 960, 'n_tokens_neox': 920, 'n_words': 379, 'path': 'Games/Monty_hall_Problem.ipynb', 'repo_name': 'AkashKV-1998/Program', 'size': '2940'}