Error: Statement expected, found Py:ELIF_KEYWORD



我是一名编程新手,我正尝试着创造一款石头剪刀布游戏。我试图让它在完成时回到开始,并打印玩家的胜利和失败数量。不断得到错误,我不知道如何修复,它变得有点令人沮丧。

任何帮助将是伟大的!:)

的错误

的代码
import random
loss = 0
wins = 0
rps = ["Rock", "Paper", "Scissors"]
op = random.choice(rps)
print(op)
while True:
pl = str(input("Choose your weapon! Rock, Paper or Scissors: ")).upper()
print(f"Wins: {wins}")
print(f"Losses: {loss}n")
if pl in ["PAPER", "P"] and op in ["Paper"]:
print(f"Opponent has chosen {op}!nIt's a draw!")
elif pl in ["PAPER", "P"] and op in ["Rock"]:
print(f"Opponent has chosen {op}!nYou Win!")
wins += 1
elif pl in ["PAPER", "P"] and op in ["Scissors"]:
print(f"Opponent has chosen {op}!nYou Lose!")
loss += 1
elif pl in ["ROCK", "R"] and op in ["Rock"]:
print(f"Opponent has chosen {op}!nIt's a draw!")
elif pl in ["ROCK", "R"] and op in ["Scissors"]:
print(f"Opponent has chosen {op}!nYou Win!")
wins += 1
elif pl in ["ROCK", "R"] and op in ["Paper"]:
print(f"Opponent has chosen {op}!nYou Lose!")
loss += 1

elif pl in ["SCISSORS", "S"] and op in ["Scissors"]:
print(f"Opponent has chosen {op}!nIt's a draw!")
elif pl in ["SCISSORS", "S"] and op in ["Rock"]:
print(f"Opponent has chosen {op}!nYou Lose!")
loss += 1
elif pl in ["SCISSORS", "S"] and op in ["Paper"]:
print(f"Opponent has chosen {op}!nYou Win!")
wins += 1

出现问题是因为最后两个elif没有缩进。因此,Python查看第一个elif并感到困惑,因为您的条件应该从if开始,但它看到了elif

在这种情况下,您有两个选项,都缩进或从if开始。

最新更新