Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Step: 3

blur-text-image

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

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions