To add a loop that runs the code 5 times, you can use a for loop. Here’s an example of how to modify your code to run the game 5 times:
import random
score_gracz = 0
score_komp = 0
for i in range(5):
print("Round ", i+1)
player = int(input("1-scissors, 2-paper, 3-rock "))
komp = random.randint(1, 3)
print("Player: ", player)
print("Komp: ", komp)
if player == komp:
print("Draw")
elif player == 2 and komp == 3:
score_komp += 1
print("You lost")
elif player == 1 and komp == 3:
score_gracz += 1
print("You won")
elif player == 1 and komp == 2:
score_komp += 1
print("You lost")
elif player == 2 and komp == 1:
score_gracz += 1
print("You won")
elif player == 3 and komp == 1:
score_komp += 1
print("You lost")
elif player == 3 and komp == 2:
score_gracz += 1
print("You won")
else:
print("Wrong choice")
print("You have", score_gracz, "points:", "Komp has", score_komp, ".\n")
print("Final score: You have", score_gracz, "points. Komp has", score_komp, "points.")
In the modified code, the for loop runs the game 5 times. At the end of each round, the scores are updated and printed. After 5 rounds, the final score is printed. Note that I also made some modifications to your original code to fix some logical errors in the game rules.