Vending Machine - Objected Oriented Design / Classics

https://algo.monster/problems/oop_vending_machine

The requirements for what is supposed to happen to the internal value are unclear, particularly in Part 3. In a real interview, we would ask questions but cannot here. What if you can use different combinations of coins to reach that amount?

You could use the fact that functions are objects in Python:

machine = Machine()
operations = { ‘new_product’ : machine.new_product,
‘print_products’: machine.print_products,
‘insert_coin’: machine.insert_coin,
‘purchase’: machine.purchase,
‘checkout’: machine.checkout }

for instruction in instructions:
if len(instruction) > 1:
operationsinstruction[0]
else:
operationsinstruction[0]

Not saying that it is better but it results in more concise code :^)

For part 3 I would ask, does checkout only spit out coins we put in? Or can we assume the machine can trade it for spare change previously in the machine?

For example, if you put in 5 pennies, can the machine spit out a nickel? Or does it have to spit out pennies because the current user only inserted pennies?