Question: Part II: Order Up! (20 points) Write a function order lunches ) that takes two arguments, in this order: 1. stock: A dictionary that contains

 Part II: Order Up! (20 points) Write a function order lunches

Part II: Order Up! (20 points) Write a function order lunches ) that takes two arguments, in this order: 1. stock: A dictionary that contains menu items available for purchase at a restaurant. The dictionary maps items to an integer count of how many of each item is available (e.g., 'soda:4) 2. orders: A list of strings representing items that patrons at the restaurant have ordered. The list might include items not available for purchase The function iterates over the orders list, treating each string in the list as a key in the stock dictionary. If the key is present in the dictionary, the function decrements the value associated with the key (provided that doing so would not make the value negative). The function also returns the total number of valid items purchased. The CSE 101 Spring 2018 Homework #4 Page 2 function simply ignore strings in orders that are not valid keys in stock. As an example, suppose stock were the dictionary f' soda' , 'burger 3, 'chips': 5, 'pizza' 7 and orders were l' soda', 'sandwich', 'burger', 'pizza', 'pizza', 'burger'. The function would update stock to f' soda': 0, 'burger': 1, 'chips' 5, 'pizza': 5) and would return 4. Note that during grading, different menu items will be used

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!