sheep door problem

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: You have a better chance of getting a car if you change it.


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: At the beginning of the selection, the probability of not changing the door is 1/3, and the probability of a car in the other two doors is 2/3. When the host opens one door, one wrong answer is excluded from the other two doors. , that is, the probability that the door is left 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)

Answer: The probability of not changing the selection is 0.33325003, and the probability of changing the selection is 0.66674997, which supports the original analysis.


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
x=eval(input("Please enter the number of times to be verified: "))
a=0
b=0
for i in range(1,x+1):
    men = random.randrange (1,4)
    che = random.randrange (1,4)
    if men==che:
        a=a+1
    else:
        b=b+1
print("The probability of not changing the selection is {}".format(a/x))
print("The probability of being selected is {}".format(b/x))

  

Guess you like

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