PythiloLesson 1 of 8 · progress kept in this browser

Round money at an explicit boundary

Binary floating point cannot represent many decimal prices exactly. Decimal constructed from text preserves the intended value. A billing rule also needs to say when rounding happens: rounding each line can differ from rounding the final total. In this exercise, add exact line amounts first and round the invoice once, using half-up rounding.

from decimal import Decimal
print(Decimal("0.10") + Decimal("0.20"))
Your task

Write invoice_total(lines). Each line is (unit_price_text, quantity). Sum using Decimal, then quantize once to two decimal places with ROUND_HALF_UP. Return a Decimal, including Decimal("0.00") for no lines.