fork download
  1. from random import randint, choice
  2.  
  3. successes, attempts = 0, 0
  4.  
  5. while attempts < 1000:
  6. correct_door = randint(0, 2)
  7. players_door = randint(0, 2)
  8. unchosen_doors = [ x for x in [0,1,2] if x != players_door ]
  9. opened_door = choice(unchosen_doors)
  10. if opened_door == correct_door:
  11. # the opened door was the winning one,
  12. # so we already lost before reaching the described scenario
  13. continue
  14.  
  15. door_to_which_we_switch = 3 - players_door - opened_door
  16. attempts += 1
  17. if correct_door == door_to_which_we_switch: successes += 1
  18.  
  19. print(successes)
Success #stdin #stdout 0.13s 14352KB
stdin
Standard input is empty
stdout
519