Sheep door problem pairing work

Job done by:

20171301071 Wei Ziye

20171301012 Wang Yining

1. Answer according to your first feeling, do you think there is 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 the odds of getting a car are higher by switching options.

2. Please carefully analyze for yourself "Is there a higher chance of getting a car if I don't change the choice, or will I have a higher chance of getting a car if I change the choice? Or the odds have not changed?"

A: After analysis, the first choice may be a car or a sheep. If you choose a car for the first time, if you change your choice, the lottery must be a sheep; if you don't change your choice, the lottery must be a car. If you choose sheep for the first time, if you change your choice, the car will be drawn. If you don't change your choice, you will definitely win a sheep. To sum up, the probability of choosing the car in the lottery is 2/3, and the probability of not choosing the car is 1/3. Therefore, the probability of getting the car is higher.

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:

import random
TIMES=eval(input("Please enter the number of times to run:"))
change=0
nochange=0
for i in range(TIMES):
    a=random.randint(0,2) #0 means the car is selected, 1, 2 means the sheep is selected
    if a==0:
        nochange=nochange+1
    else:
        change=change+1
print("Probability of no change: {}".format(nochange/TIMES))
print("Probability of changing time: {}".format(change/TIMES))

  

Guess you like

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