Question: USE PYTHON please complete this question I'm having some difficulty with this question especially with understanding the get_string function and count_matches if you could provide
USE PYTHON
please complete this question
I'm having some difficulty with this question especially with understanding the get_string function and count_matches
if you could provide comments that would be greatly appreciated!
note: this is for an intro class so please don't use advanced python methods and operators

a) This program will be exploring a list containing information about a cupboard. The list will be organized such that the first element is a string stating an item name and the second is an integer indicating the corresponding amount of cans for that item. Every subsequent entry in the list will have two parts organized in a similar fashion which means the size of the overall list will be a multiple of two. Assume every list will include information for at least one item. Here is the list format: [item name, amount of cans, ...] Here is an example illustrating the list format: ['diced tomatoes', 3, 'olives', 2, 'tomato soup', 3, 'tuna', 7] Write a program to count the total number of cans in the cupboard, display the cupboard contents, get a search string from the user, and count how many item names contain the search string given. Here are the criteria: Your program L6Qlinitials.py" must start with a commented ID Box AND include a comment that indicates the purpose of the program. EACH of the five functions in your program including the main function must state its purpose in comments too. The main function in your program must be named: explore cupboard. It has been provided for you. Copy this function into your program EXACTLY as written: def explore_cupboard (cupboard): print(" There are", count cans (cupboard), "cans") display_contents (cupboard) string = get_string() print (count_matches (cupboard, string), "items contain", string) As you can see, explore_cupboard calls FOUR helper functions. As you write your program, test each function individually with different function calls. Only move on to the next function once you are certain that your current function works. Here are the helper function specifications: count_cans (cupboard): Count and return the total amount of cans in the cupboard list. display_contents (cupboard): Print all entries in the cupboard list. Ensure all item names are displayed as uppercase. Display "1 cans" rather than 1 can" when only one can exists for a particular item (for simplicity). Refer to the screenshot for format details. get_string(): Prompt the user for a search string. Error check the string to ensure it has a length of 1 or more and is lowercase. Strip excess whitespace before returning the string. count_matches (cupboard, string): Count how many cupboard item names exactly or partially match string. Partial matches mean string is contained in the item name. Return this count. The sample output provided shows you three sample runs. Your output should be similar but reflect the list provided and the user search string. >>> explore_cupboard(['diced tomatoes', 3, 'olives', 2, 'tomato soup', 3, 'tuna', 7]) There are 15 cans -> 3 cans of DICED TOMATOES -> 2 cans of OLIVES -> 3 cans of TOMATO SOUP -> 7 cans of TUNA Enter lowercase search string of length 1 or more: 7 -> Error! Try again: T -> Error! Try again: TOM -> Error! Try again: -> Error! Try again: tom 2 items contain tom >>> explore_cupboard(['diced tomatoes', 3, 'olives', 2, 'tomato soup', 3, 'tuna', 7]) There are 15 cans -> 3 cans of DICED TOMATOES -> 2 cans of OLIVES -> 3 cans of TOMATO SOUP -> 7 cans of TUNA tuna Enter lowercase search string of length 1 or more: 1 items contain tuna explore_cupboard(['mushrooms', 3]) There are 3 cans -> 3 cans of MUSHROOMS Enter lowercase search string of length 1 or more: k 0 items contain k
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
