Objective
Create a Python program with a dataclass that has a list as a default value, using field(default_factory=list).
Instructions
- Define
@dataclass class Studentwithname: strandgrades: list[int] = field(default_factory=list), and a methodaverage(self)that returns the average of the grades, or0if there are none. - Read an integer
nand thennlines, each with a name followed by zero or more integer grades. Create each student with only the name and then add the grades withstudent.grades.append(...). - Show one line per student:
name: average, with the average to 2 decimals.
3
Ana 7 9
Luis
Eva 5 6 10
Ana: 8.00
Luis: 0.00
Eva: 7.00
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise