Recreate a vending machine. You will be given a json file of inventory, and "money" to import into your machine.
The user should input two things to get an item:
- Code (
A01
) - Amount of money the user inserts into the machine (
0.75
)
There should also be two maintenance methods:
- Check on inventory of a specific item (by code)
- The amount of money currently in the machine
Demonstrate the following rules using a test harness like PyTest, Unittest, etc.
- If the money given to the machine is less than the item cost return:
Not enough money!
- If the quantity is 0 for an item return:
<item name>: Out of Stock!
. Whereitem name
is the name of the item selected. - If an item is correctly selected return
Vending <item name> with <change> change.
Whereitem name
is the name of the item selected and change, if any, 0 otherwise. - If an item is correctly selected and there is no change needed then return:
Vending item name
. Whereitem name
is the name of the item selected. - If an invalid item is selected return
Invalid selection!
. - If a selection is successful then the quantity should be updated.
- For simplicity, denomitions of bills and coins is not taken into consideration, but the vending machine can run out of 'money', so you must keep track of the amount of money availble to return.
- Change is always given to 2 decimal places (e.g.
7.00
)
candy_machine = MyVendingMachine(json) # json = {"items": [{"name": "skittles", "code": "A01", "price": 0.60, "quantity": 11}], "money": 12.00}
candy_machine.vend('A01', 0.60)
# "Vending Skittles"
candy_machine.inventory('A01')
# "Skittles Inventory: 10"
candy_machine.money()
# "Change Available: 12.00"