Question: python exercise in exceptions: get(xs, index, response None): Consider a list of values, xs. Find and return the value at location index. If index is
python exercise in exceptions:

get(xs, index, response None): Consider a list of values, xs. Find and return the value at location index. If index is invalid for xs, return response instead. Remember that.get0 for dictionaries works gracefully for non-existing keys. Here we are implementing a get0 function for list type .Parameters: o o o xs :: list of values of any length. index :: an integer, specifying which value in the list to return. response:: a python value, to be returned when index is invalid for the list. Return value: a value from xs at index or the pre-set response Requirement: you must use try-except blocks in your solution! Examples: o get(['a','b', c'1,0) o get(['a', 'b', c'1,3) o get(['a','b','c'],4, "oops") None 'oops' 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 $10 please") ([],['That','will','be','$10','please']) ([35], ['1', 'have', 'apples']) ( [ ] , [ "Today' , "As . , ' Sunday ' ] ) 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 o > d"apple":5, "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
Get step-by-step solutions from verified subject matter experts
