2

I am writing a program for counting the score of two users. The game ends when either of them scores a ten and the respective player wins.

I wrote the while loop as:

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

and my program does not terminate.

Here is the code:

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))

1 Answer 1

3

Looks like you want

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

since you want the loop to end as soon as either one of the scores reaches 10, at which point score != 10 will be false and, consequently, the entire loop-condition will no longer be satisfied.

(score1 != 10) or (score2 != 10) would require both scores to be 10 before exiting.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.