Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import random
  2.  
  3. doors = ["goat", "goat", "goat"]
  4. right_choices_with_change = 0
  5. right_choices_without_change = 0
  6.  
  7. for attempt in range(0, 2000):
  8.  
  9.     car_position = random.randint(0, 2)
  10.     doors[car_position] = "car"
  11.  
  12.     first_choice = random.randint(0, 2)
  13.  
  14.     for door_to_open in range(0, 3):
  15.         if door_to_open != car_position and door_to_open != first_choice:
  16.             doors[door_to_open] = "opened goat"
  17.             break
  18.  
  19.     if attempt % 2 == 0:
  20.         second_choice = [door_pos for door_pos in range(0, 3) if door_pos != first_choice and door_pos != door_to_open]
  21.         if second_choice[0] == car_position:
  22.             right_choices_with_change += 1
  23.  
  24.     if attempt % 2 == 1:
  25.         if first_choice == car_position:
  26.            right_choices_without_change += 1
  27.  
  28. print("winnings without change {0}%".format(right_choices_without_change/1000*100))
  29. print("winnings with change {0}%".format(right_choices_with_change/1000*100))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement