Invoice Totals with Decimal Rounding

easy
Unit 6 · Decimal & Validation0/3 to milestone

Compute an invoice with exact decimal arithmetic. Each line is (description, quantity, unit_price, vat_rate) with prices and rates as strings (e.g. "19.99", "0.20").

Implement invoice(lines) returning a dict of Decimals:

  • net: sum of quantity * unit_price, each line rounded to 2 places with ROUND_HALF_UP
  • vat: sum of each line's VAT (line net × rate), each rounded to 2 places
  • gross: net + vat
  • vat_by_rate: a dict from rate string to the VAT total at that rate
#decimal#finance2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Invoice Totals with Decimal Rounding · TechGradify