Anonymous user
Monty Hall problem: Difference between revisions
m
Undo revision 20559 by 62.123.142.25 (Talk) -I don't think it is improved by the capitalisation of constants or the #! line.
(Forth) |
m (Undo revision 20559 by 62.123.142.25 (Talk) -I don't think it is improved by the capitalisation of constants or the #! line.) |
||
Line 550:
=={{header|Python}}==
<python>
'''
I could understand the explanation of the Monty Hall problem
but needed some more evidence
References:
http://www.bbc.co.uk/dna/h2g2/A1054306
http://en.wikipedia.org/wiki/Monty_Hall_problem especially:
http://en.wikipedia.org/wiki/Monty_Hall_problem#Increasing_the_number_of_doors
'''
from random import randrange, shuffle
def monty_hall(choice, switch=False, doorCount=doors):
door = [False]*doorCount
chosen = doors[choice]▼
door[randrange(0, doorCount)] = True
unpicked = doors▼
# Out of those unpicked, the alternative is either:▼
# the prize door, or▼
# an empty door if the initial choice is actually the prize.▼
alternative = 'car'▼
else:▼
if switch:▼
alternative = True in unpicked
return alternative▼
print "\nMonty Hall problem simulation:"
print
print "Not switching allows you to win",
print [monty_hall(randrange(
for x in
print "out of",
print "Switching allows you to win",
print [monty_hall(randrange(
for x in
print "out of",
</python>
Sample output:
|