Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import random
  2.  
  3. a_wins = 0
  4. for i in range(10**6):
  5. count = 5
  6. while count > 0:
  7. b = random.choice (["dead","not dead"]) #A shoots B
  8. if b == "dead":
  9. a_wins += 1
  10. break
  11. else:
  12. count += -1 #wasting one chance
  13. if count == 0: # If count = 0 then the A will definitly die (since we started counting from 5) hence we should leave the code
  14. break
  15. a = random.choice(["dead","not dead"]) #B shoots A
  16. if a == "dead":
  17. break #A cannot win
  18. else:
  19. count += -1 #wasting antoher chance
  20. print(a_wins/10**6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement