python while loop does not terminate -
i writing program counting score of 2 users. game ends when either of them scores ten , respective player wins.
i wrote while loop as:
while (score1 != 10) or (score2 != 10): ...
and program not terminate.
here code:
player1 = input("enter name player1") player2 = input("enter name player2") score1=0 score2=0 print ("score player1 is: %d,score player2 :%d" %(score1,score2)) while (score1 != 10) or (score2 != 10): player =input("enter name player") if player player1: score1=score1+1 if player player2: score2=score2+1 print ("score player1 is: %d,score player2 :%d" %(score1,score2))
looks want
while (score1 != 10) , (score2 != 10):
since want loop end either 1 of scores reaches 10
, @ point score != 10
false
and, consequently, entire loop-condition no longer satisfied.
(score1 != 10) or (score2 != 10)
require both scores 10
before exiting.
Comments
Post a Comment