Question: USING PYTHON 3 This program will be exploring a list containing information about a cupboard. The list will be organized such that the first element
USING PYTHON 3
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, ...]
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.
The main function in your program must be named: explore_cupboard.
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)
Here are the helper function specifications:
1) count_cans(cupboard): Count and return the total amount of cans in the cupboard list.
2) display_contents(cupboard): Print all entries in the cupboard list. Ensure all item names are displayed as uppercase. Refer to the screenshot for format details.
3) 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.
4) 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.
EXAMPLE OF OUTPUT
---------------------------------------------------------------------------------------------------------------------
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
