Choose a feasible positive-value action
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
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputcheck(p=1,benefit=4,cost=1,ready=True), dispatch(p=.9,benefit=8,cost=2,ready=False), budget=3
Output"check"
InputOne action with benefit=1, cost=2, budget=3
Outputnull
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor