Question: Problem # 4 : Inventory Manager You are a superstar inventory manager at Yamazon.com, and your work requires you to precisely keep track of every

Problem #4: Inventory Manager
You are a superstar inventory manager at Yamazon.com, and your work requires you to precisely keep track of every item's inventory. Whether it is handling a customer purchase, restocking inventory, or clearing the shelves, you have to keep track of the exact number of each and every item. We will simulate store activity by the function named inventory_manager, which will take in two parameters. The first parameter, operations, represents the list of operations that are carried out in the warehouse. The second parameter, inventory, represents the current inventory. For example, the list ['Toy Bear', 17, 'Green Boot', 20, 'Award medal', 5] represents that the warehouse currently has 17 toy bears, 20 pairs of green boots, and 5 award medals.
Possible warehouse operations:
'r:item name:amount': This is the restock operation, which means you add the provided number of some item to inventory. If the item being restocked does not exist in the inventory, add that item to the end of the inventory list.
'p:item name:amount': This is the purchase operation, which means you remove the specified number of some item from the inventory. If the item doesn't exist in the inventory, nothing happens. If the number of items requested is greater than the number in inventory, set the inventory count to 0.
'c:item name': This is the clearance operation, which means to set the inventory count of an item to 0. If that item is not in the inventory, nothing happens.
Note: These operations will be given in an argument named operations. An example of this is ['r:teddy bear:20','p:green beans:70','c:bleach'].
Complete the inventory_manger function, which iterates through all of the operations done on the inventory and returns the inventory.
Example #1
Function call:
inventory_manager(
['p:Toy bear:15','r:Cash register:20','c:Box of pencils'],
['Toy bear', 17, 'Cash register', 5, 'Box of pencils', 90])
Return value:
['Toy bear', 2, 'Cash register', 25, 'Box of pencils', 0]
Example #2
Function call:
inventory_manager(
['p:Toy bear:35','r:Cash register:17','c:Garbage can', 'p:Playstation:6'],
['Toy bear', 22, 'Cash register', 19, 'Garbage can', 25])Return value:
['Toy bear', 0, 'Cash register', 36, 'Garbage can', 0]
Example #3
Function call:
inventory_manager(
['r:Bucket:18','c:Cash register', 'r:Garbage can:7','p:Playstation:6',
'r:Peanut butter:200'],
['Toy bear', 22, 'Playstation', 10, 'Cash register', 19, 'Garbage can', 25])
Return value:
['Toy bear', 22, 'Playstation', 4, 'Cash register', 0, 'Garbage can', 32, 'Bucket', 18, 'Peanut butter', 200]
Example #4
Function call:
inventory_manager(
['c:Rakes', 'p:Doll:4','c:Shovel', 'p:Doll:2','r:Spoon:10','r:Shovel:10','p:Shirt:4',
'p:Shovel:3','r:Jelly:99'],
['Blocks',34, 'Doll', 10, 'Photocopier', 25, 'Shovel', 10, 'Shirt', 50])
Return value:
['Blocks',34, 'Doll', 4, 'Photocopier', 25, 'Shovel', 7, 'Shirt', 46, 'Spoon', 10,
'Jelly', 99]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!