1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alex_Xolod [135]
3 years ago
14

Your program is going to compare the scores of two volleyball teams that play each other. To win a match in volleyball, a team m

ust 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.
Is there a way I can do this code without using a break statement and using arrays and loops? I have this code so far but it uses break statement and doesn't use arrays. When I take away the break statement, instead of increasing in match number and stopping at 5 matches, it keeps listing match 1.

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

#loop counter
i=1

# variable to store the wins
team1_win=0
team2_win=0

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

# looping
while i <= 5:

# looping to get the valid input
while True:

Computers and Technology
1 answer:
Alenkasestr [34]3 years ago
5 0

Answer:

#section 1

team1=0

team2=0

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

for i in matches:

   print("For Game ", i)

#section 2

   while True:

       try:

           scoreA = int(input("Enter score for first team: "))

           scoreB = int(input("Enter score for second team: "))

       

           if scoreA < 25 and scoreB < 25:

               raise ValueError

           try:

               if abs(scoreA - scoreB) < 2:

                   raise  

               else:

                   break

           except:

               print("difference less than 2")

   

       except ValueError:

           print("Enter correct scores")

#section 3

       print("For Game ", i)

   if scoreA > scoreB:

       team1 = team1 + 1

   else:

       team2 = team2 + 1

#section 4

if team2 > team1:

   print("Team 2 is the winner")

else:

   print("Team 1 is the winner")

Explanation:

There is no way you can run the code without using a break statement because, in a while loop you have to pass an argument that will exit the loop. if you don't your loop will keep running and that's not good.

You might have also gone about it in a way that is a bit complicated. when writing code always look out for ways to make your work easier.

I used a For Loop, While Loop and an array.

#section 1

team1=0  

team2=0  

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

for i in matches:  

print("For Game ", i)  

- In this section two variables were declared two variables to hold the final results after both teams have played their 5 games and their scores recorded

- An Array holding the number of games they're to play was also declared. they are playing 5 so the Array "matches" holds 5 elements.

- The first loop here is the "For loop" and what it does is to run the block of code under it for all the elements in the Array.

- finally we print for game "i" where i is each game in the array

#section 2

 while True:

       try:

           scoreA = int(input("Enter score for first team: "))

           scoreB = int(input("Enter score for second team: "))

       

           if scoreA < 25 and scoreB < 25:

               raise ValueError

           try:

               if abs(scoreA - scoreB) < 2:

                   raise  

               else:

                   break

           except:

               print("difference less than 2")

   

       except ValueError:

           print("Enter correct scores")

- A while loop is always true unless it encounters an argument that is not true or a break statement is inserted.

- This section is responsible for taking all the inputs required and if a wrong input is entered it would show the specific error and ask you to make the input again.

- Here the Try and Except is use to handle the errors. When the Try block encounters an error it goes to the Except block and executes whatever it finds there.

- The first try block prompts and takes inputs, it then checks if the values inputted satisfies or violates the 25-point rule.

If it does not satisfy the 25-point rule, it goes to it's error block and prints "enter correct score" and the WHILE loop runs again.

within this Try block is nested another try block. if the first try block does not raise any error it proceeds to the second try block.

- The second Try block checks the difference between the scores and if it is less than 2, it raises an error and prints difference is less than 2 and runs the WHILE loop again.

- If there are no errors it BREAKS out of the WHILE loop then the FOR loop moves to the next match.

#section 3

       print("For Game ", i)

   if scoreA > scoreB:

       team1 = team1 + 1

   else:

       team2 = team2 + 1

- Remember there is still a for loop. This section prints the game we just recorded, and checks which team won. It then adds the win as a point(1) to the teams total score.

#section 4

if team2 > team1:

   print("Team 2 is the winner")

else:

   print("Team 1 is the winner")

- In this section the For Loop has finished running and the final values are ready, it compares the scores of both teams and declares the winner.

I have placed an attachment to help you see the code in action.

You might be interested in
The ____ criteria filter requires the records displayed to start with the specified text string
lys-0071 [83]

The "Begins With" criteria filter is what your looking for

3 0
3 years ago
Areas on which the development of the computer as a communication technology is based
Alchen [17]

Answer:

Artificial Intelligence.

Automated personal digital assistant.

THz frequencies for Communications (5G & 6G)

Blockchain.

Virtual reality and augmented reality.

Internet of Things (IoT)

Visible light communication.

LTE.

Explanation:

4 0
3 years ago
Which of the following statements is true of a cookie? a. A cookie can create copies of itself and spread to other networks to e
Ilya [14]

Answer: D.

Data about user preferences and activity is captured and stored under a cookie on a company’s Web server.

Explanation: The most common and best-known technology for user tracking is the use of cookies. Other known online website tracking tools are tracking pixels (or pixel tags), web beacons (or ultrasound beacons), and browser fingerprinting (or digital fingerprinting), amongst others.

a cookie will contain a string of text that contains information about the browser. To work, a cookie does not need to know where you are from, it only needs to remember your browser. Some Web sites do use cookies to store more personal information about you.

8 0
3 years ago
c++ Write a statement that increments (adds 1 to) one and only one of these five variables: reverseDrivers parkedDrivers slowDri
Mazyrski [523]

Answer:

The following statement are:

if(speed < 0) // if statement

{

reverseDrivers++; //if the speed is less than 0, then increment in "reverseDrivers"

}

else if(speed < 1) //else if statement

{

parkedDrivers++; //speed is less than 1, than increments in "parkedDrivers"

}

else if(speed < 40)

{

slowDrivers++; //speed is less then 40, than increment in "slowDriver"

}

else if(speed <= 65)

{

safeDrivers++; //speed is less than or equal to 40, then increment in "safeDriver"

}

else

{

speeders++; //else increment in speeders

}

Explanation:

From the following statement their are certain condition arises

If the speed is less than 0, then increments the “reverseDrivers” variable by 1.

If the speed is less than 1, then increments the “parkDriver” variable by 1.

If speed is less than 40, then increment in "slowDriver" variable by 1.

If speed is less than or equal to 40, then increment in "safeDriver" variable by 1.

Otherwise increment in "speeders"

7 0
3 years ago
Value: 3
Citrus2011 [14]

Answer:

B - A word is correctly spelled but is used incorrectly in a document

4 0
3 years ago
Other questions:
  • Refer to the exhibit. the gigabit interfaces on both routers have been configured with subinterface numbers that match the vlan
    11·1 answer
  • What are the four primary factors described in the text that set the state for Web 2.0 or the social Web that we enjoy today??
    12·1 answer
  • What kind of software consists of the programs that control or maintain the operations of a computer and its devices?
    11·1 answer
  • Convert each of the following base 10 &amp; base 2 numbers in signed magnitude, one’s complement and two’s complement. Each of t
    8·1 answer
  • ______ are used to store all the data in a database.
    7·1 answer
  • Which is a good example of kinetic energy
    14·2 answers
  • Which of the following component is required to insert text in multimedia
    8·1 answer
  • The landscape layout is more appropriate for leaflet. <br> TRUE OR FALSE
    6·1 answer
  • The cathode ray tube eventually was eventually used for what entertainment device?
    13·1 answer
  • _____ allows information to be viewed at a glance without needing to address the individual elements of the information separate
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!