Log inBook a Demo
RefactorMidBackendAuto-graded

Refactor 200 lines of pricing without changing results

Cleaning up inherited, tangled code while proving with evidence that the results are unchanged is the whole test.pricing.py holds one tangled price_order() function: nested conditionals, magic numbers scattered through the logic, and a discount branch that was copy-pasted so the member and VIP tiers compute loyalty two near-identical ways. There are no tests. Refactor it into something clean — small functions, named constants, no duplication — while keeping the numbers it returns exactly the same. Establishing that safety net before you start changing things is part of the exercise.
40 min
python

You're done when

  • Behaviour is preserved exactly — every input produces the same price it did before.
  • No function is longer than the stated limit.
  • The duplicated loyalty logic exists in one place rather than two.
  • Magic numbers are replaced with named constants that say what they mean.
  • The refactored code is genuinely simpler to read, not merely rearranged.

What it measures

Code refactoringRestructuring untested legacy code without altering what it computes.
Code qualityDecomposing into small, well-named units and eliminating duplication that has already drifted.
Working without a safety netBuilding confidence that behaviour is unchanged when no tests exist to tell you — usually by writing them first.

Your environment

Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards

Start this lab

40 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo