Your question is Vending Machine Internals. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Program a vending machine internals to accept and return cash coins.
Implement process_vending_machine(denominations, inventory, inserted, price). Return a dictionary containing accepted coins, rejected coins, change, refund, and the updated inventory. Unsupported coins are rejected. A transaction succeeds only when accepted value reaches price and the machine can make exact change from its inventory plus accepted coins. If the transaction cannot complete, refund all supported inserted coins and leave inventory unchanged.
Inputs use integer denominations, a string-keyed inventory mapping denomination to count, an inserted-coin list, and an integer price. Return change in descending order and preserve inserted order for accepted and rejected coins.
Example: [10], price 6, and four available 1 coins returns change [1,1,1,1]. If [5] is inserted for a price of 10, it is refunded.
Constraints: at most 20 denominations, at most 100 inserted coins, nonnegative counts and prices, and valid inventory keys for listed denominations.
def process_vending_machine(denominations, inventory, inserted, price):