fork download
  1. import random
  2. N = 10000
  3. def runGame(switch):
  4. choice = random.randint(0, 2)
  5. car = random.randint(0, 2)
  6. possible_doors_to_reveal = [i for i in range(3) if i not in [choice, car]]
  7. revealed_door = random.choice(possible_doors_to_reveal)
  8. if(switch):
  9. choice = [i for i in range(3) if i not in [choice, revealed_door]][0]
  10. if(choice == car):
  11. return True
  12. else:
  13. return False
  14. wins = 0
  15. for i in range(N):
  16. if(runGame(True)):
  17. wins += 1
  18. print("Switch Result: %f success" % (wins/N))
  19. wins = 0
  20. for i in range(N):
  21. if(runGame(False)):
  22. wins += 1
  23. print("Stay Result: %f success" % (wins/N))
Success #stdin #stdout 0.14s 37608KB
stdin
Standard input is empty
stdout
Switch Result: 0.673000 success
Stay Result: 0.336200 success