Sheep door operation (thunderstorm)

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: Switching options will have 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.

Answer: Assuming that there are ABC three doors, A door car, B door sheep, C door sheep, the probability of selecting a door is 1/3 (that is, the probability of selecting A in ABC is 1/3). After changing, choose A for the first time, but you cannot get a car after changing; choose B for the first time, and get a car after changing; choose C for the first time, and get a car after changing. In summary, the probability of getting the car after changing is 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: Supported.

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

code show as below:

import random
TIMES = 100000
b=0
g=0
for i in range(1,TIMES):
    a=random.choice([1,2,3])
    m=random.choice([1,2,3])
    if a==m:
        b=b+1
    else:
        g=g+1
Gb=b/TIMES
Gg =g/ TIMES
 print ( " The probability of getting a car without changing the choice is {} " .format(Gb))
 print ( " The probability of getting a car with changing the choice is {} " .format(Gg))

 

Guess you like

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