Question: Hello, I am having trouble with this code. The output is only showing results for Match 1 instead of Matches 1, 2, 3, 4, 5.

Hello, I am having trouble with this code. The output is only showing results for Match 1 instead of Matches 1, 2, 3, 4, 5. How do I get the code to show results for all 5 matches?

Here are the instructions below, the code, and the output.

Your program is going to compare the scores of two volleyball teams that play each other. To win a match in volleyball, a team must get 25 points. But the team must also win by 2. So even if a team reaches 25, that game continues until one team is ahead by 2 points. Let's assume that these two teams are going to play five matches.

Your program should accept

from the user the scores for each team one match at a time. If at any time that

user enters scores that violate the 25-point rule or the "win by 2"

point rule, print an error on the screen and make the user enter both scores

again.

When the user is finished

entering the scores, the program should print which team won the game. This is

the team that won the most matches.

You have to use arrays and

loops in this assignment.

print("Welcome to the volleyball score program.")

i = 1

team1_win = 0

team2_win = 0

matches = [1, 2, 3, 4, 5]

while i <= 5:

diff = 0

while diff < 2:

team1 = int(input("Enter the number of points Team 1 got in Match %d " % i))

team2 = int(input("Enter the number of points Team 2 got in Match %d " % i))

if team1 >= 25 or team2 >= 25:

diff = abs(team1 - team2)

if diff >= 2:

if team1 > team2:

team1_win += 1

else:

team2_win += 1

else:

print("That can not be. One team must win by 2 points. Please reenter the data.")

else:

print("That can not be. One team must get at least 25 points. Please reenter the data.")

i += 1

if team1_win > team2_win:

print("Team 1 has won the game.")

else:

print("Team 2 has won the game.")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!