Scoreboard by Rounds
Implement a class RoundScoreboard that records points for a group of players, one round at a time. Write these methods:
RoundScoreboard(players)sets up the board for the names inplayers. No round has been played yet.add_round(points)records one round, in whichplayers[i]scoredpoints[i]. Returns how many rounds have been recorded, counting this one.total_for(name)returns the sum ofname's points over all recorded rounds (0before the first round).last_round_for(name)returns whatnamescored in the most recent round, or0if no round has been recorded yet.best_total()returns the highest total of any player (0before the first round).
name is always one of the players.
The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
RoundScoreboard(["kai","lu"])
add_round([3,5]) returns 1
add_round([4,0]) returns 2
total_for("kai") returns 7
total_for("lu") returns 5
last_round_for("lu") returns 0
best_total() returns 7
kai scores 3 and 4 for a total of 7; lu scores 5 and then 0, so the last round for lu is 0. The best total is 7.
Constraints
1 <= len(players) <= 5- The names in
playersare different, each1to8lowercase letters. len(points) == len(players)and0 <= points[i] <= 20- Each test makes
1to30method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Classes problems
- Stack With a Size LimitBeginner
- Take a NumberBeginner
- Tally CounterBeginner
- Thermostat Between Two LimitsBeginner
- Whose Turn Is ItBeginner
- Average of the Last K ReadingsEasy
- Call Limiter per UserEasy
- Clinic Waiting RoomEasy