Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- a_wins = 0
- for i in range(10**6):
- count = 5
- while count > 0:
- b = random.choice (["dead","not dead"]) #A shoots B
- if b == "dead":
- a_wins += 1
- break
- else:
- count += -1 #wasting one chance
- if count == 0: # If count = 0 then the A will definitly die (since we started counting from 5) hence we should leave the code
- break
- a = random.choice(["dead","not dead"]) #B shoots A
- if a == "dead":
- break #A cannot win
- else:
- count += -1 #wasting antoher chance
- print(a_wins/10**6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement