222k views
0 votes
Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2, the message "player1 wins" is printed to standard out. When score2 exceeds score1, the message "player2 wins" is printed to standard out. In each case, the variables player1Wins,, player1Losses, player2Wins, and player2Losses,, are incremented when appropriate.

Finally, in the event of a tie, the message "tie" is printed and the variable tieCount is incremented.
So far this is what I have:
if score1>score2:
player1Wins=player1Wins+1
player2Losses=player2Losses+1
print("player1Wins")
elif score2>score1
player2Wins=player2Wins+1
player1Losses=player1Losses+1
print("player2Wins")
else:
score1=score2
tieCount=tieCount+1
print("tie")
___________________________
However, I'm still getting an error and not sure why. Am I indenting something wrong?

User Abl
by
7.7k points

1 Answer

4 votes

Answer:

player1Wins = player1Losses = player2Wins = player2Losses = tieCount = 0

score1 = 10

score2 = 10

if score1>score2:

player1Wins=player1Wins+1

player2Losses=player2Losses+1

print("player1 wins")

elif score2>score1:

player2Wins=player2Wins+1

player1Losses=player1Losses+1

print("player2 wins")

else:

tieCount=tieCount+1

print("tie")

Step-by-step explanation:

Since your indentation can not be understand what you give us, please try to do it as you see in the answer part.

Although it seems that this is a part of the code, it is normal that you get errors. However, since you keep track of the variables, it is better to initialize the variables that will keep the counts. Since initially, they are 0, you may set them as 0. Also, if you assign the values to the scores, probably you would not get any error. This way, you may test your code as I did.

Other than these, in the else part you do not need to write "score1=score2", because if score1 is not greater than score2 and if score2 is not greater than score1, this already implies that they are equal

User ZekeDroid
by
6.4k points