I have this code that randomly selects an item in the list and matches each other following a rule. I would like to repeat the matches N times, and count how many events occurred stored in variables tie and diff.
The problem is that, at the moment, it repeats N times the same results, not a different match. If I sate range(10) it will repeat the same match result 10 times. I would like to repeat the match N times, not the same result.
import random
rules = ['rock', 'paper', 'scissors']
pc1 = random.choices(rules)
pc2 = random.choices(rules)
tie = 0
diff = 0
def match():
if pc1 == pc2:
return False
print('tie')
if pc1 != pc2:
return True
print('different')
for _ in range(10):
if match() == False:
tie +=1
if match() == True:
diff +=1
print(tie, diff)
Aucun commentaire:
Enregistrer un commentaire