**Reference:-** https://en.wikipedia.org/wiki/Monty_Hall_problem

### Problem Statement

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)

### Standard Assumption:-

- The host must always open a door that was not picked by the contestant (Mueser and Granberg 1999).
- 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.

### 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.

#### General Confusion

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 an equal probability.

To break 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 goat_door=[] switch_win=0#No. of times player wins by switching stick_win=0#No. of times player wins by sticking to initial choice j=0 while j<100000: x=random.randint(0,2) #xth door comprise of the prize doors=["GOAT"]*3 #switching xth door with car doors[x]="CAR" for i in range(3): if doors[i]!="CAR": goat_door.append(i) #Appending all goat_door index to list ch=random.randint(0,2) host_door=random.choice(goat_door) while host_door==ch: host_door=random.choice(goat_door) swap=random.randint(0,1) #To know whether player swaps or not if(swap==1): if doors[ch]=="GOAT": switch_win=switch_win+1 else: if doors[ch]!="GOAT": stick_win=stick_win+1 j=j+1 doors.clear() goat_door.clear() print(switch_win,stick_win)

#### Output:-

**Note:-**In above image, it can be seen that the no. of chances of win almost doubles up by swapping. No. of iterations can also be increased to get a more accurate result.

## 0 Comments