Created
August 18, 2016 04:33
-
-
Save adrianmoses/7ea33e72911b317a514a4d6cf6ec1756 to your computer and use it in GitHub Desktop.
Monty Hall Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def expose_goat(doors, sel_index): | |
for i in doors: | |
if i != sel_index: | |
choice = doors[sel_index] | |
if choice == 'goat': | |
print "Door %s is a goat" % i | |
return i | |
def assign_doors(): | |
choices = ['goat', 'goat', 'car'] | |
random.shuffle(choices) | |
doors = {i: choice for i, choice in enumerate(choices)} | |
return doors | |
if __name__ == "__main__": | |
doors = assign_doors() | |
sel_door = raw_input("Select Door 0, 1, or 2: ") | |
sel_door = int(sel_door) | |
print "You chose Door #%d" % sel_door | |
goat_door = expose_goat(doors, sel_door) | |
switch_door = raw_input("Do you want to switch? (y/n) : ") | |
door_nos = doors.keys() | |
if switch_door == "y": | |
sel = [dn for dn in door_nos if dn not in [sel_door, goat_door]][0] | |
else: | |
sel = sel_door | |
print "You choose a %s" % doors[sel] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment