Objective
Create a Python program that combines an enumeration and a dataclass to group items by category.
Instructions
- Define
class Category(Enum)withFOOD = 1,TOOLS = 2andTOYS = 3, and@dataclass class Itemwithname: str,price: intandcategory: Category. - Read an integer
nand thennlines with the formatname price code, wherecodeis the value of the category (converted withCategory(int(code))). - For each category, in the order of the enumeration, show
NAME: T, with the sum of the prices of its items (0 if it has none). - At the end show
Total: X, with the sum of all the prices.
4
pan 2 1
martillo 15 2
leche 1 1
coche 20 3
FOOD: 3
TOOLS: 15
TOYS: 20
Total: 38
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise