为什么我的程序在使用了两个Else If语句一次后会跳过它们



我正在创建一个程序,该程序持续跟踪回合胜利,直到用户输入"退出";。对于我的错误,当我为任何一个玩家赢得一场胜利时,程序就会工作。当我输入多个点时,程序会说谁的点最多。例如,我给了玩家2两轮胜利,而给了玩家1一轮胜利,同样的问题也会发生,反之亦然。该程序不会打印谁赢得最多回合。

这是我的代码:

points1 = 0
points2 = 0
total1 = 0
total2 = 0
player1 = input("Enter first player name: ")
player2 = input("Enter second player name: ")
while True:

descision = int(input("***n1-enter a new round winnern2-check who has the most winsn"))

if descision == 1:

player = input("Who has won this round?")

if player == player1:
total1 = points1 + 1
elif player == player2:
total2 = points2 + 1
elif int(descision) == 2 and total1 == 0 and total2 == 0:
print("No games played yet.")
elif int(descision) == 2 or total1 != 0 or total2 != 0:
if total1 > total2:
print(player1 + " has the most wins so far.")
elif total1 < total2:
print(player2 + " has the most wins so far")
elif str(descision) == "exit":
break

在第18行和第20行中,您应该增加总分,您总是设置"合计";至1只需将其更改为

total1 = total1 + 1
total2 = total2 + 1

最新更新