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.
Let's write a function to model a simple warehouse accounting
system, which maintains the inventory for a set of commodities. 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.
It may be useful to review Relevant Readings aboout how to define custom functions.
Next Exercise: Averages