Log inBook a Demo
DebugJuniorBackendAuto-graded

Fix invoice totals that drift by a cent

Finance found invoice totals off by a cent; make every amount exact and round half-up, keeping the same signatures.billing.py totals invoices: line totals, a percentage tax and a flat discount. Finance says the numbers are a cent out. A $2.045 line comes out as 2.04, and the sample invoice totals 149.01 where the hand total is 149.02. Every amount should be correct to the penny, rounding half-up on the half-cent. Keep the function signatures and the return type: a money string with exactly two decimals, like "19.99" or "5.00".
25 min
Python

Goals

  • Every line total is the unit price times the quantity, rounded once to the cent, half-up: a $2.045 line is 2.05, a $1.005 line is 1.01, and three units at $0.335 are 1.01.
  • The invoice subtotal adds the line totals after each one is rounded, so a $2.045 line and a $3.005 line come to 5.06, not 5.05.
  • The invoice total (subtotal, plus the percentage tax, minus the flat discount) is correct to the penny and rounds half-up, including when the tax lands on a half-cent: the sample invoice in billing.py totals 149.02.

What it measures

PythonWriting numeric code that returns the exact amount every time.
Debugging and profilingFinding where a one-cent difference comes from and fixing it there.
Care with moneyTreating the rounding rule, and when rounding happens, as part of the spec.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

25 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo