Python Sheep door work

Source: Internet
Author: User

1, I think will increase the probability of the selection.

The reasons are as follows:

If the selection is not replaced, the probability of the player selecting the car is 1/3;

If the selection is changed, the probability of the contestant selecting the car is 1/3*0+2/3*1=2/3.

2, the program source code is as follows:

From random Import *

def once (doors = 3): # Simulation of a single event

Car = randrange (doors) # There's a car parked behind a door

Man = Randrange (doors) # Contestants pre-Select a door

return car = = Man # did the contestants first choose to go to the car
h = 0 # Keep Choosing the number of times you win a car

c = 0 # Change the number of times you choose to win a car

times = Int (1e6) # Number of repetitions of the experiment
For I in Range (times):

If once (): H + = 1

Else:c + = 1

Print ("Maintain selection:", h/times*100, "%\n Change Selection:", c/times*100, "%")

3. The verification result of the operation is as follows:

Python Sheep door work

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.