Workspace/Coding labs
Loading progress

Parse a strict arithmetic request

Intermediate50 min

Implement parse_request(text). Accept at most 4096 characters, plain JSON or one exact outer fence starting with triple-backticks plus json and a newline, ending with newline plus triple-backticks. Strip outer whitespace first. Require exactly operation and values. Operation is sum or max. Values is a list of 1–20 actual integers from -1000 through 1000; booleans and floats are not integers for this contract. Reject duplicate object keys and nonstandard constants such as NaN. Raise ValueError on invalid input. Do not evaluate code or infer missing values.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

InputJSON sum with values [2,3]

OutputThe parsed object

All schema gates pass.
EXAMPLE 2

InputJSON sum with values [true]

OutputValueError

Boolean is not an exact integer under the contract.
solution.pyPython 3.12