About the sheep door

There are 3 closed doors, one with cars parked behind and the rest with goats, only the host knows what is behind each door. Contestants can choose a door, and before opening it, the host will open another door, revealing the goat behind the door, and then allow the contestant to change their choice.

High chance of getting a car

First define, 1 is a car, 2 and 3 are sheep. Change: choose 1, change, get the car. Choose 2, change, get the car. Choose 3, change, get the car. Do not change: choose 1, do not change, get the car. Choose 2, if you don't change, you won't get a car. Choose 3, if you don't change, you won't get a car. So, the chance of changing is 2/3, and the chance of not changing is 1/3.

The code was done with the help of others, validating my own results.

The probability of getting a car without changing the choice is about 0.33446745562130176.

The probability of changing the choice to get a car is about 0.6655325443786982.

 

import random
x = random.randint (500,10000 )
bubian = 0
bian = 0
for i in range(1,x+1):
    a = random.randrange (1,4 )
    b = random.randrange (1,4 )
     if a == b:
          bubian =bubian+1
     else :
          bian= bian+1 
c =bubian/ x
d =bian/ x
 print ( " The probability of getting a car without changing the choice is about {}. " .format(c))
 print ( " The probability of getting a car with a choice is about {}. " .format(d))
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325256782&siteId=291194637