Code RoomRounding order affects total
HardPrep Room Coding #1961

Rounding order affects total

Code reviewCode quality & reviewSenior–Staff~20 min

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.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1def round_cents(amount):
2 # amount is a float number of dollars, e.g. 2.675
3 return round(amount, 2)
4 
5def invoice_tax(line_amounts, rate):
6 total = 0.0
7 for amt in line_amounts:
8 tax = amt * rate # e.g. 26.75 * 0.10 = 2.675
9 total += round_cents(tax)
10 return round_cents(total)
11 
12# invoice_tax([26.75], 0.10) -> ledger expects 2.68
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.