Advertisement
Guest User

Door Test

a guest
Sep 16th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import random
  2.  
  3. wins = 0
  4. losses = 0
  5.  
  6. for i in range(1000000):
  7.     # "So you have 3 doors..."
  8.     doors = [0,0,0]
  9.     # doors
  10.     # "One of them is the correct answer"
  11.     doors[random.randrange(0, 3)] = 1
  12.     # doors
  13.     # "You pick one of the doors"
  14.     selection = random.randrange(0, 3)
  15.     # selection
  16.     # "One of the incorrect choices gets removed"
  17.     while len(doors) == 3:
  18.         randomDoor = random.randrange(0, 3)
  19.         # The door only gets removed if it is not a winner and it is not the door the player picked
  20.         if doors[randomDoor] == 0 and randomDoor != selection:
  21.             doors.pop(randomDoor)
  22.             # Shift the player's choice to account for updated indices
  23.             if randomDoor < selection:
  24.                 selection -= 1
  25.     # doors
  26.     # "Did I win?"
  27.     if doors[selection] == 1:
  28.         wins += 1
  29.         # "Yes!"
  30.     else:
  31.         losses += 1
  32.         # "No!"
  33.  
  34. print "Wins:"
  35. print wins
  36. print "\nLosses:"
  37. print losses
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement