Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use PYTHON only and follow all the following instructions carefully. Thank you Please make sure that it can pass all the test cases as

Please use PYTHON only and follow all the following instructions carefully. Thank you

image text in transcribed

Please make sure that it can pass all the test cases as follows: https://repl.it/Mz3C/2

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

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_2

Step: 3

blur-text-image_3

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 Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago