Analysis of the problem of sheep door

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?

Answer: Change.

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: If you don't change it, there is a 1/3 chance of getting the car. If you change it, the host will tell a sheep, then there will be one sheep and a car left to choose from (you won't be stupid enough to choose the sheep told by the host), and the probability of getting a car will increase to 1/2. So change
3. Result analysis: The probability of

getting a car without changing: 0.34 The probability
of getting a car: 0.50

The probability of getting a car without changing is about 1/3, and the probability of getting a car is 1/2. Support the above question Analysis

4. Program code:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 26 19:28:53 2018

@author: Administrator
"""
import random
sum_nc=0;
sum_c=0;
for i in range(1,10001):
    car_nc=random.randint(0,2);#If you don't change, there are three possible positions of the car, choose one as the position of the car
    nc=random.randint(0,2); #Similarly , people have three choices
    if nc==car_nc: #If the position of the car is the same as the position guessed by the person, add 1 to the count variable
        sum_nc+=1;
    car_c=random.randint(0,1);#If you change it, there are two possibilities for the position of the car, choose one as the position of the car
    c=random.randint(0,1);#Similarly, people have two choices
    if car_c==c:
        sum_c+=1;#Same as above
sum_nc/=10000;
sum_c/=10000;
print("Probability of not getting a car: {:.2f}".format(sum_nc));
print(" Changed Probability of getting a car: {:.2f}".format(sum_c));

Guess you like

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