Sheep door work

Title description: There are 3 closed doors, behind one door is parked cars, behind the rest are 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?

Switching options has a higher chance of getting a car

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.

If the first selection is either of the two doors with sheep, when the host gives the other door with sheep, change the selection at this time, and the car will be selected. There are a total of two doors with sheep behind them, so the result is 2/3. There is a greater chance of switching options

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)

import random
TIMES=10000
n=0
for i in range(TIMES):
    a=random.randint(1,3)
    if a==1:
       n=n+1
    if a==2:
       n=n+1
    if a==3:
       n=n+0
print(n)

 

Guess you like

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