Code Room
Code reviewHard
Question
Review this Python that rounds each line's tax to cents and totals an invoice that must reconcile against an external ledger using standard 'round half up'.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
def round_cents(amount): # amount is a float number of dollars, e.g. 2.675 return round(amount, 2) def invoice_tax(line_amounts, rate): total = 0.0 for amt in line_amounts: tax = amt * rate # e.g. 26.75 * 0.10 = 2.675 total += round_cents(tax) return round_cents(total) # invoice_tax([26.75], 0.10) -> ledger expects 2.68Run or narrate your approach, then ask the coach.