Carts and sheep (this is a good question)

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: The odds have not changed.

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: The probability of replacement will be greater. The probability of not getting the car is 1/3. If you do, the sheep will be chosen at the beginning, and the car will be chosen the second time. The final probability is 2/3*1=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: Run 100 times, the result is 0.36, 0.64.

      Run 1000 times and the result is 0.332, 0.668.

     10000 runs, 0.3327, 0.6673.

     100000 runs, 0.3339, 06661. Support my analysis.

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

 
 
import random
x=eval(input())
huan = 0
buhuan=0
for i in range(1,x+1):
  a = random.randint (1,3 )
  b=random.randint(1,3)
  if a==b:
    buhuan =buhuan+1
   else :
    huan =huan+1
 print ( " The probability of getting a car without changing the choice is {} " .format(buhuan/ x))
 print ( " The probability of getting a car by changing the choice is {} " .format(huan/x))
 
 

 

 

 

Guess you like

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