Inventory report
Given a of Item dataclasses, write report(items) that returns a multi-line : one line per item as NAME padded to 12 chars, quantity right-aligned in 4, and total value (qty × price) right-aligned in 9 with two decimals; then a final line TOTAL followed by the grand total in the same 9-wide column. Sort items by name.
Examples
bolt 40 10.00 washer 100 5.00 TOTAL 15.00
Exercise
3 checksInventory report
from dataclasses import dataclass
@dataclass
class Item:
name: str
qty: int
price: float
def report(items):
...
stock = [Item("washer", 100, 0.05), Item("bolt", 40, 0.25)]
print(report(stock))
Press Run to try your code, then Check answer to grade it.