Sheep door work 1

---Restore content begins---

Job done by:

Student ID: 20171301065, Heli Pan

Student ID: 20171301069, Wang Yajie

 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.

A: The first time I chose a car, I changed it to a sheep, not a car.

 The first time I chose a sheep, I changed it to a car, not a sheep.

The first time I chose a sheep, I changed it to a car, not a sheep.

There are three cases for getting a car, and there is one case for not getting a car, the probability is 1/3. There are two cases of getting a car in exchange, the probability 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: Running result:

Please enter the number of runs: 1000000  

Probability not changing: 0.332539

 Probability of changing time: 0.667461

It can be seen that the supporting analysis results

4. Please attach your code. (Hint: Use the insert code function in the editor to display the code in Python style) The code is as follows:

#Y represents the number of times you can get a car by changing, and N represents the number of times you can get a car without changing
import random
TIMES=eval(input("Please enter the number of times to run:"))
Y=0
N=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:
        N=N+1
    else:
        Y=Y+1
print("Probability of not changing: {}".format(N/TIMES))
print("Probability of changing time: {}".format(Y/TIMES))

  

 

---End of recovery content---

Guess you like

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