question 212 Modules & Packages · easy
Fix the receipt line imports
receipt_line should format one line of a receipt using the provided market package, but it stops with ImportError: cannot import name 'line_total' from 'market'. Fix it. Once the import works, test it with an unknown SKU too. Provided files sit next to your program (they aren't editor tabs); print(Path("market/__init__.py").read_text(encoding="utf-8")) shows one's source.
Function
receipt_line(sku, quantity)Returns
"<name> x<quantity>: <line total>", e.g. 'Deluxe Pillow x2: 95.98'; for a SKU the catalogue doesn't have, 'unknown SKU <sku>'market/__init__.py
from .catalog import find_product, so from market import find_product worksmarket/catalog.py
find_product(sku) → the product's dictionary (name, price as text, category) or None; it knows HOM-52782 Deluxe Pillow 47.99, BOO-58412 Nordic Handbook 15.99 and GRO-63674 Pro Honey 5.00market/money.py
cents(amount) rounds a Decimal or decimal text to the cent, half up; line_total(price_text, quantity) → cents(Decimal(price_text) * quantity)Examples
callreceipt_line('HOM-52782', 2)returns'Deluxe Pillow x2: 95.98'
callreceipt_line('GRO-63674', 3)returns'Pro Honey x3: 15.00'