Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python, must use try/ except blocks Please comment thought process classify(input_string): It takes as input a string with a mixed group of integers and

In Python, must use try/ except blocks

Please comment thought process

image text in transcribed

classify(input_string): It takes as input a string with a mixed group of integers and words separated by spaces. It returns a tuple of two lists: a list of integers and a list of non-empty words. Use exceptions to distribute words and integers to their respective lists. Note: do NOT include empty string in the return list; any string that does not include an integer only (e.g. '$10' or '3.00) should be classified as words Hint: check what happens when you call int0 on strings like '3.00'. .Parameter: input string: string with a group of integers and words separated by spaces. Return value: a tuple of a list of integers(int) and a list of words(string) Requirement: you must use try-except blocks in your solution! .Examples: O classify("I have 35 apples") O classify("Today is Sunday") o classify( "That will be $1e please") ([35], ['l', 'have', 'apples']) ( [ ] , [ "Today' , ' is ' , ' Sunday' ] ) ([],['That','will", 'be','$10','please']) 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. o product_list: a list of tuples, each tuple has two members: a string as the product name and an integer as the amount. 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", 20), ("pear", -10), ("grape" ,18)] >> shelve(d,ps) pear 20, "grape 18, orange: 25, apple 70) >> shelve(d, [("apple", -1000)]) 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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions