Question: in Python use try/ except shelve(inventory, product_list): Given a dictionary, inventory, and a list of tuples product_list, we need to update the inventory with products
in Python
use try/ except

shelve(inventory, product_list): Given a dictionary, inventory, and a list of tuples product_list, we need to update the inventory with products listed in product_list: if a product is already in store, update the amount; if the product is not in store, add a new entry in inventory for it. We might also call this function to update inventory when the stock amount is decreased. But if the amount of any product is below zero, we must raise a ValueError with the "negative amount for product" message. Parameters: o inventory : a dictionary with product name (string) keys and product amount (int) values. product_list:a list of tuples, each tuple has two members: a string as the product name and an integer as the amount. o Returns: None. You should make update to inventory in-place. Raises: ValueError when the amount of a product is below zero. Examples: d {"apple" : 50, "pear": 30, "orange" :25) >>> >>> ps = [("apple" ,29), ( "pear",-10), ("grape",18)] >>shelve(d,ps) o pear 20, grape: 18, 'orange 25, 'apple': 7e) shelve(d, ("apple", -1000)1) Traceback (most recent call last): ValueError: negative amount for apple
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
