Question

In: Computer Science

IN PYTHON Write a function called check_inventory(inventory, low) that passes a dictionary as inventory and low...

IN PYTHON

Write a function called check_inventory(inventory, low) that passes a dictionary as inventory and low as an integer, and returns a sorted list of items that are below an inventory level that is given by thelowinteger parameter. The function should work without the low parameter supplied - in which case, you should assume low is 5. You do not have to worry about reading and writing to a file, that code is provided, and you don’t have to change it. Example: If the inventory is {'banana':3,'apple':10}, check_inventory(inventory) will return the list['banana'] and print it in the output file. For the same inventory, check_inventory(inventory, 15) will return the list ['apple','banana'] and print it out in the output file.

Solutions

Expert Solution

I had written only the function for inventory since it is said that the file reading is given there you just need to call the function. If you have any queries write a comment. If understood upvote Thank you.

SOLUTION:

##define function with a default value of low as 5
def check_inventory(inventory,low=5):
result=[]##intialize the result list
for key in inventory:##iterate through the dictionary
if(inventory[key]<low):##if value is less than low
result.append(key)##append to list
result.sort()##sort the list
return result##result the list

##inventory dictionery
inventory={'banana':3,'apple':10}
print(check_inventory(inventory))## call the inventory function with out low
print(check_inventory(inventory,15))##call the inventory with low
  
CODE IMAGE: ## called with low and without low

OUTPUT:


Related Solutions

Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145'
Python pls create a function called search_position. This function returns a dictionary. team1 = {'Fiora': {'Top':...
Python pls create a function called search_position. This function returns a dictionary. team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} def search_position(team1): should return {'Top': {'Fiora': 1, 'Yasuo':5,'Olaf':3,'Shaco':}, 'Jungle': {'Shaco': 4}, 'Mid': {'Yasuo', 2, 'Fiora': 4,'Olaf':2}, 'Bottom': {'Fiora': 3}, 'Support': {'Olaf': 4}} *******IMPORTANT*************** The result should be alphabetical order.
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the given wordlist  An anagram dictionary has each word with the letters sorted alphabetically creating a “key”.
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called glossary. Have the glossary include a list of five (5) programing words you have learned in chapters 4-6. Use these words as keys to your dictionary. Find the definition of these words and use them as the values to the keys. Using a loop, print each word and its meaning as neatly formatted output. Create three dictionaries called person. Have each of the person...
Write a python function that will return the total length of line that passes through any...
Write a python function that will return the total length of line that passes through any number of provided points ( (x,y) ). The points should be passed as individual tuples or lists. The function should also have a parameter (True or False) to indicate whether the line should start from the origin, and that parameter should default to False. If True, the returned value should include the distance from the origin to the first point, otherwise start adding distances...
This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names...
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names to addresses. A person's name (stored as a string) will be the KEY and that person's address (stored as a string) will be the VALUE. 1.2) Insert into the dictionary 'addresses' the names and addresses of two (possibly imaginary) friends of yours. 1.3) Create a second empty dictionary called 'ages'. The dictionary you just created will map names to ages. A person's name (stored...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
In python of Jupiter notebook Write a python function called trng that takes three numbers x,...
In python of Jupiter notebook Write a python function called trng that takes three numbers x, y, and z, and specifies if those can form a triangle (i.e., returns the word triangle if they can, and Not a triangleotherwise). Note: In order for three numbers to form a triangle sum of any two of them must be greater than the third one (e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not greater than z even though x+z>y...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT