Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DOORS=['A','B','C']
- ALL_WIN=DOORS
- CHOOSE=DOORS
- total_wins=total_loss=0
- stay_win=stay_loss=0
- switch_win=switch_loss=0
- def did_i_win(chosen_door, the_car):
- if chosen_door == the_car:
- return True
- else:
- return False
- def show_results(fc, reveal, swap, car):
- if swap == fc: swap = '-'
- print "Car: %s Choice: %s Reveal: %s Change: %s win=%s" \
- %(car, fc, reveal, swap, did_i_win(swap, car))
- def stay(my_door, revealed, car):
- if did_i_win(my_door, car):
- global stay_win
- stay_win+=1
- global total_wins
- total_wins+=1
- else:
- global stay_loss
- stay_loss+=1
- global total_loss
- total_loss+=1
- show_results(my_door, revealed, my_door, car)
- def switch(my_door, revealed, car):
- switch_list = [(g) for g in DOORS if g <> my_door and g <> revealed]
- # change the one-element [0] list to a string
- switch = switch_list[0]
- if did_i_win(switch, car):
- global switch_win
- switch_win+=1
- global total_wins
- total_wins+=1
- else:
- global switch_loss
- switch_loss+=1
- global total_loss
- total_loss+=1
- show_results(my_door, revealed, switch, car)
- for winning_door in DOORS:
- for choice in CHOOSE:
- monty_choices = [(g) for g in DOORS if g <> winning_door and g <> choice]
- for reveal in monty_choices:
- stay(choice, reveal, winning_door)
- switch(choice, reveal, winning_door)
- print
- print
- print "%s stay and win" % stay_win
- print "%s stay and lose" % stay_loss
- print "%s switch and win" % switch_win
- print "%s switch and lose" % switch_loss
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement