Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Tournament: A sports tournament. === Attributes === teams: The names of the teams in this tournament. team_stats: The history of each team in this

class Tournament: """A sports tournament.

=== Attributes === teams: The names of the teams in this tournament. team_stats: The history of each team in this tournament. Each key is a team name, and each value stores the number of games played and the number won.

=== Sample usage === >>> t = Tournament(['Team A', 'Team B', 'Team C']) >>> t.record_game('Team A', 'Team B', 10, 4) >>> t.record_game('Team A', 'Team C', 5, 1) >>> t.record_game('Team B', 'Team C', 2, 0) >>> t.team_stats['Team B'] [2, 1] >>> t.team_stats['Team A'] [2, 2] >>> t.team_stats['Team C'] [2, 0] """ # Attribute types teams: List[str] team_stats: Dict[str, List[int]]

def __init__(self, teams: List[str]) -> None: """Initialize a new Tournament among the given teams. """ self.team_stats = {} self.teams = teams

for team in self.teams: self.team_stats[team] = [0, 0]

def record_game(self, team1: str, team2: str, score1: int, score2: int) -> None: """Record the fact that played with the given scores.

scored and scored in this game.

Precondition: team1 and team2 are both in this tournament. """ # Recall that the values in team_stats are lists in the form # [# games played, # of wins] # And that the keys are the team names.

# Record that a game has been played for both teams.

# Record that a game was won for the team with a higher score. # If there is a tie, no win is recorded.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

What is database?

Answered: 1 week ago

Question

What are Mergers ?

Answered: 1 week ago