Sheep door pairing work

Job done by:

20171301081 Gao Qiyue

20171301083 Hu Siyu

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: I think swapping 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.

A: After analysis, there is a higher chance of getting a car by swapping.

Analysis: The probability of choosing a car for the first time is 1/3, the probability of choosing a car after changing is 0, the probability of choosing a car without changing is 1*1/3, and the probability of choosing a sheep for the first time is 2/3 , the probability of getting a car after changing is 1/2, the probability is 2/3*1/2=1/3, the probability of getting a car without changing is 0, and the probability of getting a car is 1/3+1/3= 2/3. The probability of getting a car without changing is 1/3+0=1/3

To sum up: the probability of getting a car in exchange is greater.

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:

Please enter the number of runs: 500000
Probability of getting a car without changing: 0.33238 Probability
of getting a car when changing: 0.66762

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

import random
TIMES=eval(input("Please enter the number of times to run: "))
A=0
B=0
for i in range(TIMES):
    a = random.randint (0.2)
    if a==0:
        A=A+1
    else:
        B=B+1
print("Probability of getting a car without changing: {}".format(A/TIMES))
print("Probability of getting a car when changing: {}".format(B/TIMES))

  

Guess you like

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