Log inBook a Demo
BuildSeniorBackendAuto-graded

Fix a transfer that loses or invents money

Rebuild a ledger transfer so balances stay exact, never go negative, and a refused transfer changes nothing.ledger.py keeps account balances, and transfer(frm, to, amount) moves money between them. Since it shipped, finance has seen balances off by fractions of a cent, accounts below zero, and days where the total across all accounts changed even though money only moves between them. Fix transfers so they're exact to the cent, the ones that should fail are refused, and a refused transfer leaves both accounts as they were. Keep the public interface unchanged.
40 min
python

You're done when

  • The total across all accounts stays the same after every transfer.
  • No account ever goes below zero.
  • A transfer larger than the source balance is refused with an error.
  • A refused transfer leaves both accounts as they were, with no partial debit or credit.
  • Self-transfers, unknown accounts and zero or negative amounts are refused with an error.
  • Final balances are exact to the cent, with no floating-point drift.

What it measures

Back-end developmentKeeping amounts exact and making every transfer either complete in full or change nothing.
Test case designFinding the inputs that break the ledger: overdrafts, unknown accounts, self-transfers, awkward cent amounts.
Reasoning about correctnessChecking that the books still balance after every transfer, including the ones that get refused.

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

40 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