Discussion on the problem of sheep door

Job done by:

Student ID: 20171301016 , Feng Jingyuan

Student ID: 20171301004 , Li Ziwei

 

 

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 first impression is that the odds are the same.

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: The probability of selecting a car when not changing: one-third (there is no change, so the probability of selecting a car at the beginning is the same)

        The probability of selecting a car when changing is: two-thirds (here are discussed in two cases: the first is that the car is selected at the beginning, and then the car is not selected at this time, this probability is one-third. The second case is that the sheep is selected at the beginning, and the car can be selected as long as the exchange is performed, and the probability of selecting the sheep at the beginning is two-thirds, so the probability of selecting the car by exchanging is two-thirds.)

       Therefore, this problem can be reduced to the probability of the first choice of the selected car.

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 verifications: 100000

The probability of choosing a car after swapping is: 0.66688

The probability of not swapping the selected car is: 0.33312

The results of its operation support our 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
a=[0,1,0]
i=0
n1=0
n2 = 0
times =eval(input( " Please enter the verification times: " ))
 while i< times:
  door1=random.choice(a)
  if door1!=1:
      n1=n1+1
  else:
    n2 =n2+1 
  i =i+1
 print ( " The probability of selecting a car after swapping is: {} " .format(n1/ times))
 print ( " The probability of not exchanging the selected car is: {} " .format(n2 /times))

 

 

 

 

 

 

 

5. Expansion of ideas ( I hope the teacher can see if it is correct or not )

In the process of searching from the Internet, I found a question related to its expansion. In the question, 1 car was changed to n cars, and 1 sheep was changed to m sheep, and then I thought about the problem.

( 1 ) Ideas:

Probability of getting a car without changing cars: n/(n+m)

Probability of getting a car when changing cars: {[n/(m+n)]*[(n-1)/(m+n-2)]}+{[m/(m+n)]*[n/ (m+n-2)]}

( 2 ) Running result:

Number of sheep: 2

Number of cars: 1

Enter the number of quizzes : 10000

If you choose not to change, the probability of getting a car is: 0.3359

If you choose to change, the probability of getting a car is: 0.6641

( 3 ) Code:

 

import random
sheep =eval(input( ' Number of sheep: ' ))
car =eval(input( ' Number of cars: ' ))
num =eval(input( ' Enter the number of quizzes: ' ))
s=sheep+car
i=0
ncar = 0
ncar1=0
ncar2=0
while i<num:
    x=random.randint(1,s)
    if x<=car:
        ncar=ncar+1
        s1=car+sheep-2
        x=random.randint(1,s1)
        if x<=car-1:
            ncar1=ncar1+1
    else:
        s2=car+sheep-2
        x=random.randint(1,s2)
        if x<=car:
            ncar2 =ncar2+1 
    i =i+1
 print ( ' If you choose not to change, the probability of getting a car is: {} ' .format(ncar/ num))
 print ( ' If you choose to change, the probability of getting a car is: {} ' . format((ncar1/num)+(ncar2/num)))

 

Guess you like

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