Question: purchase ( self , item, qty = 1 ) Attempts to buy something from the vending machine. Before completing the purchase, check to make sure
purchaseself item, qty
Attempts to buy something from the vending machine. Before completing the purchase, check to
make sure the item is valid, there is enough stock of said item, and there is enough balance.
Output in order of priority
str
Invalid item if the item id is invalid Highest priority
Machine out of stock is returned if the machine is out of stock for all items
Item out of stock is returned if there is no stock left of requested item.
Current itemid stock: stock, try again if there is not enough stock
Please deposit $remaining if there is not enough balance
Item dispensed if there is no money to give back to the user
Item dispensed, take your $change back if there is change to give back
depositself amount
Deposits money into the vending machine, adding it to the current balance.
Output
str Balance: $balance when machine is stocked
Machine out of stock. Take your $amount back if the machine is out of stock.
restockself item, stock
A protected method that adds stock to the vending machine. Note that when the VendingMachine
runs out of a product, a Vendor object will trigger the operation using its restock method already
implemented for you
Output
str Current item stock: stock for existing id
Invalid item is returned if the item id is invalid.
isStockedself
A property method behaves like an attribute that returns True if any item has any nonzero stock,
and False if all items have no stock.
Output
bool Status of the vending machine.
getStockself
A property method behaves like an attribute that gets the current stock status of the machine.
Returns a dictionary where the key is the item and the value is the list price stock
Output
dict Current stock status represented as a dictionary.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
