Goat door Problem

Source: Internet
Author: User

Goat door Problem

Question: There are three closed doors, one with a car closed and the other two with goats. The host knows what is behind each door. First, the contestant chooses a door. Before opening the door, the host opens one door from the other two doors to reveal the goat behind the door. In this case, contestants are allowed to change their choices. Can contestants have the opportunity to guess a car after changing their choice? Please design and compile the program for verification and give your own explanations. The answer should be given in the following way.

A: I think it will increase the probability of selecting a car.

The reason is as follows: if the option is not changed, the probability of a car being guessed is 1/3. If the option is changed, if the option is selected for the first time, the probability of a car being selected is 1/3; if Yang 2 is selected for the first time, the probability of a car to be replaced is 1/3. If a car is selected for the first time, the probability of a car to be replaced is 0, the probability of a player guessing a car is 2/3.

The program source code is as follows:

Import random
X = eval (input ("enter simulation times :"))
Car = 0
Car1 = 0

For I in range (1, x + 1 ):
A = random. randrange (1, 4)
B = random. randrange (1, 4)

If a = B:
Car1 = car1 + 1
Elif! = B:
Car = car + 1
Print ("the probability of selecting a car after the change is", car/x)
Print ("do not change the probability of the selected car to", car1/x)

The verification result is as follows:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.