Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice? (Whitaker, 1990, as quoted by vos Savant 1990a)
The host must always open a door to reveal a goat and never the car.
The host must always offer the chance to switch between the originally chosen door and the remaining closed door.
Note:-Try to solve yourself first before heading towards the solution.
In standard assumptions the probability of winning a car is 2/3 by switching.It can be seen by the behavior of the host.Let’s analyze From below it can be seen that if a person switches his/her choice he/she will be more likely to win.
Although it can be proved using conditional probability and baye’s theorem many people still think that switching doesn’t matter.Both unopened doors will have the equal probability. To broke this assumption let’s prove it by Python Program.
Implementation of Problem using Python
#Monty Hall Problem
#Various comments are used to improve readability of code
import random#To choose and guess the probability of winning.
doors=["GOAT"]*3#Initializing each door with door
switch_win=0#No. of times player wins by switching
stick_win=0#No. of times player wins by sticking to initial choice
x=random.randint(0,2) #xth door comprise of the prize
doors=["GOAT"]*3 #switching xth door with car
for i in range(3):
goat_door.append(i) #Appending all goat_door index to list
swap=random.randint(0,1) #To know whether player swaps or not
Note:-In above image it can be seen that the no. of chances almost doubles by swapping.No. of iterations can be increased to get more accurate result.