2013-07-11 124 views
2

我正在编写一个程序来计算两个用户的分数。当他们中的任何一个得分为10并且相应的玩家获胜时游戏结束。python虽然循环不终止

我写的while循环:

while (score1 != 10) or (score2 != 10): 
    ... 

和我的程序不会终止。

下面是代码:

player1 = input("Enter name for Player1") 
player2 = input("Enter name for Player2") 
score1=0 
score2=0 


print ("Score for Player1 is: %d,Score for player2 is :%d" %(score1,score2)) 

while (score1 != 10) or (score2 != 10): 
    player =input("enter name for player") 

    if player is player1: 
     score1=score1+1 
    if player is player2: 
     score2=score2+1 
    print ("Score for Player1 is: %d,Score for player2 is :%d" %(score1,score2)) 

回答

2

看起来像你想

while (score1 != 10) and (score2 != 10): 

,因为你想要的分数的一方达到10循环尽快结束,在这一点score != 10会为false,因此,整个循环条件将不再满足。

(score1 != 10) or (score2 != 10)需要得分为10退出前。

+1

谢谢,这有帮助。:) – RamyaV