在下面的石头剪刀布程序中,我的循环有问题。使用设置长度的输入,每组游戏进行 N 次。对于结果为玩家 2,计算机 0 的情况;玩家 0,电脑 2;播放器 2,计算机 5;玩家 0,电脑 4;一个额外的游戏被添加到集合中。我已经多次更改功能,无法弄清楚出了什么问题。
def rpsls_play():
print("Welcome to the Rock-Scissors-Paper-Lizard-Spock game!")
player_sets=0
N=int(input("Select set length: "))
times=0
player_wins=0
computer_wins=0
while times < N:
times +=1
print("Now beginning game", times)
if rpsls_game()==1:
player_wins +=1
else:
computer_wins +=1
print("Set score: Player", str(player_wins)+", Computer", str(computer_wins))
else:
pass
if player_wins==computer_wins:
while abs(player_wins-computer_wins)<2:
times +=1
print("Now beginning game", times)
if rpsls_game()==1:
player_wins +=1
else:
computer_wins +=1
print("Set score: Player", str(player_wins)+", Computer", str(computer_wins))
else:
pass
if player_wins>computer_wins:
print("Congratulations! You have won in", times, "games.")
player_sets +=1
elif computer_wins>player_wins:
print("Too bad! You have lost in", times, "games.")
pass
感谢您的帮助