Objective
Create a Python program with a sortable dataclass: with order=True, the objects are compared by their attributes, in the order in which they are declared.
Instructions
- Define
@dataclass(order=True) class Playerwithpoints: intandname: str, in that order. - Read an integer
nand thennlines with the formatname points. - Sort the players from highest to lowest with
sorted(players, reverse=True). They are compared first by points and, if tied, by name. - Show the ranking, one line per player, with the format
N. name (points), starting at 1.
3
ana 50
luis 80
eva 65
1. luis (80)
2. eva (65)
3. ana (50)
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise