Workspace/Coding labs
Loading progress

Execute only a typed arithmetic tool

Foundation50 min

Implement execute_tool(name, arguments) for exactly two tools, add and multiply. Each takes exactly a and b, exact integers in [-100,100]. Return {'ok': True, 'value': result} for success. Return {'ok': False, 'error': code} with code unknown_tool, invalid_shape, or invalid_value, checking in that order. Never evaluate text or dynamically import a callable.

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

Inputexecute_tool("multiply", {"a": 6, "b": 7})

Output{"ok": true, "value": 42}

A valid named operation executes.
EXAMPLE 2

Inputexecute_tool("add", {"a": true, "b": 1})

Output{"ok": false, "error": "invalid_value"}

Boolean is not a domain integer.
solution.pyPython 3.12