Question

In: Computer Science

9.11 LAB: Winning team (classes) Complete the Team class implementation. For the class method get_win_percentage(), the...

9.11 LAB: Winning team (classes)

Complete the Team class implementation. For the class method get_win_percentage(), the formula is:
team_wins / (team_wins + team_losses)

Note: Use floating-point division.

Ex: If the input is:

Ravens
13
3 

where Ravens is the team's name, 13 is the number of team wins, and 3 is the number of team losses, the output is:

Congratulations, Team Ravens has a winning average!

If the input is Angels 80 82, the output is:

Team Angels has a losing average.

------------------------------------------------------------------------------------------------------------------------------------

We are given:

class Team:
def __init__(self):
self.team_name = 'none'
self.team_wins = 0
self.team_losses = 0

# TODO: Define get_win_percentage()


if __name__ == "__main__":
  
team = Team()

team_name = input()
team_wins = int(input())
team_losses = int(input())
  
team.set_team_name(team_name)
team.set_team_wins(team_wins)
team.set_team_losses(team_losses)
  
if team.get_win_percentage() >= 0.5:
print('Congratulations, Team', team.team_name,'has a winning average!')
else:
print('Team', team.team_name, 'has a losing average.')

Please help, in Python!

Solutions

Expert Solution

class Team:
    def __init__(self):
        self.team_name = 'none'
        self.team_wins = 0
        self.team_losses = 0

    def set_team_name(self, team_name):
        self.team_name = team_name

    def set_team_wins(self, team_wins):
        self.team_wins = team_wins

    def set_team_losses(self, team_losses):
        self.team_losses = team_losses

    # TODO: Define get_win_percentage()
    def get_win_percentage(self):
        percent = self.team_wins / (self.team_wins + self.team_losses)
        return percent


if __name__ == "__main__":

    team = Team()

    team_name = input()
    team_wins = int(input())
    team_losses = int(input())

    team.set_team_name(team_name)
    team.set_team_wins(team_wins)
    team.set_team_losses(team_losses)

    if team.get_win_percentage() >= 0.5:
        print('Congratulations, Team', team.team_name, 'has a winning average!')
    else:
        print('Team', team.team_name, 'has a losing average.')

SCREENSHOT

OUTPUT


Related Solutions

7.26 LAB: Nutritional information (classes/constructors) Given main(), complete the FoodItem class (in files FoodItem.h and FoodItem.cpp)...
7.26 LAB: Nutritional information (classes/constructors) Given main(), complete the FoodItem class (in files FoodItem.h and FoodItem.cpp) with constructors to initialize each food item. The default constructor should initialize the name to "None" and all other fields to 0.0. The second constructor should have four parameters (food name, grams of fat, grams of carbohydrates, and grams of protein) and should assign each private field with the appropriate parameter value. Ex: If the input is: M&M's 10.0 34.0 2.0 1.0 where M&M's...
7.27 LAB: Artwork label (classes/constructors) Given main(), complete the Artist class (in files Artist.h and Artist.cpp)...
7.27 LAB: Artwork label (classes/constructors) Given main(), complete the Artist class (in files Artist.h and Artist.cpp) with constructors to initialize an artist's information, get member functions, and a PrintInfo() member function. The default constructor should initialize the artist's name to "None" and the years of birth and death to 0. PrintInfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Complete the Artwork class (in files Artwork.h and Artwork.cpp) with constructors...
Complete the implementation of the Die class. Note that the Die class uses an array to...
Complete the implementation of the Die class. Note that the Die class uses an array to represent the faces of a die. You need to complete the no-argument constructor and the two methods compareTo and equals. Code: import java.util.Arrays; import java.util.Objects; import java.util.Random; /* * NOTE TO STUDENTS: * The constructor that you need to complete can be found on line 47. * * The two methods you need to complete can be found at the end of this file....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
Ch 5 Program 1: Sphere.java                Complete the implementation of the Sphere class based on the Diagram...
Ch 5 Program 1: Sphere.java                Complete the implementation of the Sphere class based on the Diagram below. Use the DecimalFormat class in Sphere.java to format your output in the toString method. Then download the tester application SphereTester.java from canvas to test your Sphere class. Do not change SphereTester.java. Sphere private double radius //radius of the sphere object private static int numSpheres //static or class variable. All Sphere objects share it public Sphere() //constructor . Initialize Sphere objects’ instance variable radius...
Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class...
Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class Fibonacci { // Fib(N): N N = 0 or N = 1 // Fib(N-1) + Fib(N-2) N > 1 // For example, // Fib(0) = 0 // Fib(1) = 1 // Fib(2) = Fib(1) + Fib(0) = 1 + 0 = 1 // Fib(3) = Fib(2) + Fib(1) = Fib(2) + 1 = (Fib(1) + Fib(0)) + 1 = 1 + 0 + 1...
We started creating a Java class for Car. In this lab we are going to complete...
We started creating a Java class for Car. In this lab we are going to complete it in the following steps: 1- First create the Car class with some required instance variables, such make, model, year, price, speed, maxSpeed, isOn, isMoving, and any other properties you like to add. 2- Provide couple of constructors for initializing different set of important properties, such as make, model, year, and price. Make sure that you do not repeat initialization of instance variables in...
Define the classes to complete dynamic array hierarchy with a concrete, abstract and interface class. public...
Define the classes to complete dynamic array hierarchy with a concrete, abstract and interface class. public class DArray { private int array[]; public DArray() { } private void expandArray() { } private void shrinkArray() { } } --------------------------------------------------------------- public abstract class ArrayBP { protected int numElements; protected int numAllocations; public abstract void storeAt(int item, int index) { } public abstract getFrom(int index) { } public abstract int len() { } public abstract void remove();{ } public abstract void removeAt(int index)...
For the eMAR implementation, it has been determined that an implementation team needs to be formed...
For the eMAR implementation, it has been determined that an implementation team needs to be formed to better understand the needs related to barcoded medication administration at the hospital. 1. Which of the following would you select to be on the four-person implementation team? Explain your answer. i. Chief Executive Officer (CEO) - in charge of the direction and management of the entire organization ii. General Counsel - chief attorney for the hospital iii. Senior Information Services Leader - oversees...
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static...
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static methods for performing common DNA-based operations in * bioinformatics. * * */ public class BasicBioinformatics { /** * Calculates and returns the reverse complement of a DNA sequence. In DNA sequences, 'A' and 'T' * are complements of each other, as are 'C' and 'G'. The reverse complement is formed by * reversing the symbols of a sequence, then taking the complement of each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT