Я только начал изучать python пару месяцев назад, и у меня возникают трудности с утверждением elif в моей программе. Предполагается, что это игра «Камень, бумага, ножницы», в которую можно играть с компьютером. Между ними у вас будут отличные дисплеи, такие как счет игрока и компьютер, так как программа отслеживает результаты игры. В конце концов, вы должны иметь окончательный счет, что тоже круто.
К сожалению, я не могу запустить мою программу из-за неверной синтаксической ошибки для моего оператора elif. Не уверен, почему я получаю эту ошибку, особенно после проверки и двойной проверки несколько раз. Я надеялся, что, может быть, кто-то из вас поможет разобраться в этой глупой проблеме. Я специально получаю сообщение об ошибке (elif computer == "Rock") в скрипте. Ниже я также покажу весь код для более широкого понимания происходящего.
from random import randint
player_wins = 0
computer_wins = 0
winning_score = 2
while player_wins < winning_score and computer_wins < winning_score:
print(f"Player score: {player_wins}", "Computer score: {computer_wins} ")
print("...Rock...")
print("...Paper...")
print("...Scissors...")
player = input("(Enter your choice): ").lower()
random_num = randint(0, 2)
if (random_num == 0):
computer = "Rock"
elif (random_num == 1):
computer = "Paper"
else:
computer = "Scissors"
print(f"The computer plays: {computer}")
# Automation for the computer to play
if player == computer:
print("It's a tie")
elif player == "Rock":
if computer == "Paper":
print("Computer wins!")
computer_wins += 1
# returns a + 1 for the computer_wins value to help keep track of score
else:
print("Player Wins")
player_wins += 1
if player == "Paper":
elif computer == "Rock":
print("Player Wins")
player_wins += 1
# returns a + 1 for the player_wins value to help keep track of score
else:
print("Computer Wins")
computer_wins += 1
if player == "Paper":
elif computer == "Scissors":
print("Computer Wins")
computer_wins += 1
else:
print("Player Wins")
player_wins += 1
if player == "Scissors":
elif computer == "Paper":
print("Player wins")
player_wins += 1
else:
print("Computer Wins")
computer_wins += 1
if player == "Scissors":
elif computer == "Rock":
print("Computer Wins")
computer_wins += 1
else:
print("Player Wins")
player_wins += 1
if player == "Rock":
elif computer == "Scissors":
print("Player Wins")
player_wins += 1
else:
print("Computer Wins")
computer_wins += 1
else:
print("Please enter a valid move!")
if player_wins > computer_wins:
print("CONGRATS YOU WON!")
else:
print("OH NO, :( THE COMPUTER WON...")
print(f"FINAL SCORES... Player: {player_wins} Computer...{computer_wins}")