Warehouse
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
As an intern for Wearhausen Houseware Company, you have been asked to write a function which will help Wearhausen Houseware's warehouse keep an accounting of its current inventory. We will represent the commodities by strings, e.g. 'anvils'
, 'bricks'
, and 'cinder blocks'
.
There will be transactions on the warehouse which either increase or decrease the amount of a commodity.
('receive', 'anvils', 10)
represents a transaction that increases the amount of'anvils'
by 10('ship', 'anvils', 5)
represents a transaction that decreases the amount of'anvils'
by 5
We will keep track of the inventory with a dictionary, where keys are the commodity names and values are the current amounts. For example, if the warehouse has 10 units of 'anvils'
, 20 'bricks'
, and 400 'cinder blocks'
, we have {'anvils': 10, 'bricks': 20, 'cinder blocks': 400}
.
Write a function warehouse_process
that takes two arguments:
- a dictionary representing the warehouse inventory
- a Python list of transactions, each of one of the two forms above
Your function should return None
, but it should mutate the inventory dictionary to reflect all of the transactions. (We'll revisit functions like this in next week's readings.)
Make sure to handle the case for a receive
transaction when the commodity is not yet present in the dictionary; simply treat
the current total for that commodity as zero. Assume that there will
always be enough supply to fill all the ship
transactions.
For example:
inventory = {}
warehouse_process(inventory, [('receive', 'labrador retrievers', 10), ('ship', 'labrador retrievers', 7)])
print(inventory) # this should print {'labrador retrievers': 3}
Next Exercise: Delivery Pricing