在下面的岩石剪刀程序中,我的循環出了問題。使用輸入設定長度,遊戲每次播放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
感謝您的幫助
我需要的線路,因爲如果出現平局,他們必須打,直到一個由兩輪問題的勝率,由於某種原因遊戲正在當不存在聯繫時添加 – user2906979
英語不是我的母語,我認爲你不僅需要'player_wins == computer_wins'而且還需要'abs(player_wins-computer_wins)<2'的額外遊戲。我用'random'測試'rpsls_game()'來測試你的代碼(python 2.x,3.x),而且我沒有看到問題。這個對我有用。它只有在'player_wins == computer_wins'時纔會增加額外的遊戲。 – furas
也許你在一個文件中進行了修改,但是不小心你用舊代碼運行了不同的文件。 – furas