CLICK THE IMAGE TO VIEW SIMULATION
Monte Carlo Simulation of the Monty Hall Problem
To simulate the Monty Hall problem using a Monte Carlo approach to estimate the probabilities of winning a car based on two different strategies: USING PYTHON SIMULATION TECHNIQUES
Switching: The contestant always switches their choice after the host reveals a goat.
Sticking: The contestant always sticks with their initial choice.
Number of Trials (n): The number of times the simulation will be run to gather enough data for reliable probability estimation.
Theoretical probabilities for the Monty Hall problem are well-known:
Switching: The probability of winning the car by always switching should converge to approximately 2/3 (about 66.67%).
Sticking: The probability of winning the car by always sticking with the initial choice should converge to approximately 1/3 (about 33.33%).
The actual outcomes of the Monte Carlo simulation are displayed as two lists tracking the probabilities of winning when switching and sticking, respectively, over the number of trials. These outcomes are plotted to visualize how the probabilities stabilize as the number of trials increases.
Initialization: Set up the doors with one car and two goats, and initialize lists to store win probabilities for both strategies.
Simulation Loop:
Shuffling: Randomly shuffle the doors for each trial.
Contestant's Initial Choice: Randomly choose one of the three doors.
Host's Action: Identify and open a door with a goat that is not the contestant's initial choice.
Switch Choice: Determine the remaining unopened door for the switch strategy.
Outcome Determination: Check if the initial or switched choice wins the car and update the win counts accordingly.
Probability Update: Calculate and store the running probabilities of winning for both strategies.
Plotting: After completing the trials, plot the probabilities of winning for both strategies against the number of trials, with theoretical probabilities marked as reference lines.
Results Printing: Print the final calculated probabilities of winning for both strategies.
PROBABILITY ANALYSIS
PROBABILTY CALCULATED MANUALLY:
The probability of winning the car by always switching = 2/3 =0.6666
The probability of winning the car by always sticking = 1/3 =0.3333
PROBABILTY CALCULATED THROUGH SIMULATION {BY TAKING N = 1000
The probability of winning the car by always switching = 0.6635
The probability of winning the car by always sticking = 0.3365