Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a good or bad 'simulation' for Monty Hall? How come?
    primarykey
    data
    text
    <p>Through trying to explain the <a href="http://en.wikipedia.org/wiki/Monty_Hall_problem" rel="noreferrer">Monty Hall problem</a> to a friend during class yesterday, we ended up coding it in Python to prove that if you always swap, you will win 2/3 times. We came up with this:</p> <pre><code>import random as r #iterations = int(raw_input("How many iterations? &gt;&gt; ")) iterations = 100000 doors = ["goat", "goat", "car"] wins = 0.0 losses = 0.0 for i in range(iterations): n = r.randrange(0,3) choice = doors[n] if n == 0: #print "You chose door 1." #print "Monty opens door 2. There is a goat behind this door." #print "You swapped to door 3." wins += 1 #print "You won a " + doors[2] + "\n" elif n == 1: #print "You chose door 2." #print "Monty opens door 1. There is a goat behind this door." #print "You swapped to door 3." wins += 1 #print "You won a " + doors[2] + "\n" elif n == 2: #print "You chose door 3." #print "Monty opens door 2. There is a goat behind this door." #print "You swapped to door 1." losses += 1 #print "You won a " + doors[0] + "\n" else: print "You screwed up" percentage = (wins/iterations) * 100 print "Wins: " + str(wins) print "Losses: " + str(losses) print "You won " + str(percentage) + "% of the time" </code></pre> <p>My friend thought this was a good way of going about it (and is a good simulation for it), but I have my doubts and concerns. Is it actually random enough?</p> <p>The problem I have with it is that the all choices are kind of hard coded in.</p> <p><strong>Is this a good or bad 'simulation' for the Monty Hall problem? How come?</strong></p> <p><strong>Can you come up with a better version?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload