Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago