The Ledger That Leaked Cents — Python Bug Hunt
Inspired by every audit that ever found the books off by a few cents — because prices took a round-trip through binary floating point.
- Language: Python
- Layer: Database
- Difficulty: Easy
- Concepts: Floating Point, Money
- Modelled on: Floating-point money lore
- Visible tests: the classic 19.99 is exact; sub-dollar prices are exact; whole and single-decimal prices pad
- Reward: 50 XP for a complete fix
Briefing
Inspired by every audit that ever found the books off by a few cents — because prices took a round-trip through binary floating point. 19.99 * 100 is 1998.9999…, and int() finishes the crime.
prices.py parses price strings into integer cents. No floats allowed anywhere.
Bug report
BUG-1CENT · Priority: High · Reported by: finance close
parse_cents(price) — strings with exactly 0–2 decimals:
- "19.99" -> 1999
- "0.29" -> 29
- "5" -> 500
- "7.5" -> 750
Observed: "19.99" parses to 1998. Every 19.99 sale leaks a cent.
Logs
[close] ledger drift this quarter: -$142.17The code as shipped
src/fin/prices.py (editable)
# Parses a price string into integer cents.
def parse_cents(price):
return int(float(price) * 100)
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.