BuildSeniorBackendAuto-graded
Evaluate arithmetic with correct precedence and parentheses
Interpreting written arithmetic correctly from scratch, with no built-in shortcut available to lean on, is the requirement.Implementevaluate(expr) so it correctly evaluates arithmetic: the four operators, unary minus, parentheses, integer and decimal literals, with proper precedence and left-associativity. Malformed input and division by zero must raise EvalError. The shipped version evaluates strictly left to right — so 2 + 3 * 4 comes out as 20 — ignores parentheses entirely, and does not handle unary minus. Reaching for the language's own eval is not a solution here.45 min
python
You're done when
- Ordinary expressions produce the correct value.
- Operator precedence and parentheses are both respected, so multiplication binds tighter and brackets override.
- Unary minus is handled, including where it leads an expression or follows an operator.
- Malformed input raises
EvalErrorrather than returning something plausible. - Division by zero raises
EvalError.
What it measures
Algorithm designBuilding a parser that encodes precedence and associativity, rather than scanning left to right and hoping.
Attention to detailCovering unary minus, nested parentheses and the error cases, each of which is easy to leave out and easy to test.
Solving rather than sidesteppingImplementing the evaluation instead of delegating to the language, which is the whole point of the exercise.
Your environment
Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards
Start this lab
45 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