sheep door problem

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.

1. Answer according to your first feeling. Do you think you have a higher chance of getting a car if you don’t change the choice, or do you think you can get a car with a choice? Or the odds haven't changed?

A: According to my first feeling, it is a higher chance of getting a car by changing the choice.

2. Please carefully analyze "Is there a higher chance of getting a car if I don't change the choice, or is there a higher chance of getting a car if I change the choice? Or the probability has not changed?" Write down your analysis ideas and results.

A: Switching options will have a higher chance of getting a car.

Idea: First, the probability that the player selects the door for the first time is one-third. Therefore, when the player has already selected the car door and listens to the host to change, the probability of winning the prize is 0. The first and second times are zero.
Secondly, the probability of a player selecting Yangmen for the first time is two-thirds. At this time, when the contestant selected the sheep door, the host has already opened another sheep door, that is to say, the remaining one must be the car door. Therefore, once the player changes his choice, he must hit the door to win the prize, and his probability of winning is 1. The first and second time are two-thirds.
The total probability is 0+2/3=2/3.

3. Please try to write a program to verify your ideas. The verification results support your analysis results, or do not support your analysis results. Please write the program running results and whether they support your analysis. (Hint: This procedure can be done with the help of the random number function)

A: Support my results.

The result of the operation is that the probability of changing the selection is greater than 0.6668

The probability of not changing the choice is 0.3331

 

4. Please attach your code. (Hint: Use the Insert Code feature in the editor to display the code in Python style)

import random
a=0
b=0
TIMES=1000000
for i in range(TIMES):
    c=random.randint(1,3)#1, 2 indicate that there is a sheep behind the door, and 3 is a car.
    if c==1 or c==2:#If the sheep is selected for the first time, it must be a car after changing the selection.
        a=a+1
    else:#If the first choice is a car, it must be a sheep after changing the choice.
        b=b+1
print("The probability of not changing the choice is: {}".format(b/TIMES))
print("The probability of changing the choice is: {}".format(a/TIMES))

 

  

 

Guess you like

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