import random
import time
moves=["rock", "paper", "scissors"]
# Initially setting the score to 0
comp_wins = player_wins = 0
# while none of them reaches a score of 4 this loop will continue
# if either of them gets a score of 4 we terminate the loop
while comp_wins<4 and player_wins<4:
play_move = str(input("Please choose rock, paper, or scissors: "))
computer_move= moves[random.randint(0, 2)]
print("Ready...")
# time.sleep(1)
print("Set...")
# time.sleep(1)
print("GO!")
# time.sleep(1)
ties= 0
if play_move == computer_move:
print("Both players chose", play_move, "and there is a tie, please play again")
ties = ties+1
elif play_move == "rock":
if computer_move == "paper":
print(computer_move, "beats", play_move, "You have lost!")
comp_wins = comp_wins+1
else:
print(play_move, "beats", computer_move, "You have won!")
player_wins = player_wins+1
elif play_move == "paper":
if computer_move == "scissors":
print(computer_move, "beats", play_move, "You have lost!")
comp_wins = comp_wins+1
else:
print(play_move, "beats", computer_move, "You have won!")
player_wins = player_wins+1
elif play_move == "scissors":
if computer_move == "rock":
print(computer_move, "beats", play_move, "You have lost!")
comp_wins = comp_wins+1
else:
print(play_move, "beats", computer_move, "You have won!")
player_wins=player_wins+1
else:
print("Your selection was invalid please try again")
Я добавил цикл с комментариями. Сначала мы объявили
comp_wins = player_wins = 0
Так что мы можем получить к ним доступ в цикле while.
while comp_wins<4 and player_wins<4:
Теперь в цикле while мы проверяем, ниже ли оба их балла 4. Как только любой из них набирает 4, мы прекращаем.