Workspace/Coding labs
Loading progress

Choose a feasible positive-value action

Intermediate65 min

Implement choose_action(actions, budget). Each action has unique nonempty name, exact bool allowed and ready, finite nonnegative cost, probability p in [0,1], and finite benefit. Budget is finite and nonnegative. Reject malformed numeric values and booleans as numbers. Rank feasible actions with cost <= budget by utility p*benefit-cost; break ties by name. Return the highest positive-utility action name, or None if no feasible action has positive utility. Feasibility always precedes ranking.

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

Inputcheck(p=1,benefit=4,cost=1,ready=True), dispatch(p=.9,benefit=8,cost=2,ready=False), budget=3

Output"check"

The unready high-utility action is excluded.
EXAMPLE 2

InputOne action with benefit=1, cost=2, budget=3

Outputnull

The explicit abstention policy rejects nonpositive utility.
solution.pyPython 3.12