In: Computer Science
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!
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