Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Place your answer to this problem in the burger.py le) Burgers-To-Go has hired you to develop a new food ordering system for its customers. Each

(Place your answer to this problem in the burger.py le) Burgers-To-Go has hired you to develop a new food ordering system for its customers. Each customer will type in a code representing the structure of his or her order, and your program will calculate the total cost of the order. An order code is dened as a (case-sensitive) string of letters; each letter represents some element of the burger (the protein type, a topping, or a condiment). The valid codes for protein types, toppings, and condiments are as follows: Protein Letter Patty Type Price B Beef $2.00 T Turkey $2.50 V Veggie $2.25 Toppings ($0.50 each) Letter Topping l Lettuce t Tomato o Onion p Pickle j Jalapeo peppers c Cheese b Bacon s Sauted onions m Sauted mushrooms f Fried onions Condiments (free) Letter Condiment k Ketchup u Mustard y Mayonnaise a A.1. steak sauce q Barbecue sauce For example, "Tpmlmy" represents a turkey burger with pickle, heavy/extra sauted mushrooms, lettuce, and mayonnaise ($4.50), while "Bcbqq" represents a beef hamburger with cheese, bacon, and heavy/extra barbecue sauce ($3.00). Complete the burger() function, which takes a single string parameter representing a customer order. This function returns either a number or a string, depending on the contents of its parameter. Your function should process its parameter one character at a time (a for loop is a good way to do this), keeping track of several values: The type of protein that has been ordered The total number of toppings that have been ordered The total number of condiments that have been ordered A valid order MUST include exactly one protein, plus up to ve toppings and up to two condiments. The elements of an order may be arranged in any order; for example, condiments and toppings may be mixed together, with the protein type at the end. Toppings and condiments may be repeated (indicating extra quantities of that topping or condiment); repeating a topping or condiment still counts toward the limit for that type of element, so 3 t (tomato) characters will only allow the customer to add up to 2 additional toppings (likewise, 2 copies of a single condiment means that no additional condiments may be ordered). - If the parameter string is a valid order (exactly one protein, 05 toppings, and 02 condiments), your function should return a oat representing the total cost of the order: protein_cost + (0.5number_of_toppings) (dont worry if the cost doesnt have exactly two digits after the decimal point) - If the order is invalid because it contains too many protein types (or no protein type at all), or because it contains too many toppings or condiments, your function should return theexactstring invalid order (all lowercase). - Iftheparameterstringcontainsaninvalidcharacter(e.g.,anx,whichisnotpresentinanyofthethreetablesabove), your function should immediately terminate and return theexactstring unrecognized order code (all lowercase). Hint: You can simplify your classication tests by using the in operator with a single string that holds all the valid letters for that category. For example, letter in "BTV" will return True if the variable letter matches any protein type. Your general logical structure will probably look something like the following: protein "" toppings 0 condiments 0 For each character in the parameter: If the current character is a protein type: Ifproteiniscurrently"",setittothecurrentcharacter(andoptionallyrecordthepriceinanewvariable) Otherwise, return an "invalid order" message (to reect the extra protein) Otherwise, if the current character represents a topping: If toppings is less than 5, increment its value by 1 Otherwise, return an "invalid order" message (to reect too many toppings) Otherwise, if the current character represents a condiment: If condiments is less than 2, increment its value by 1 Otherwise, return an "invalid order" message (to reect too many condiments) Otherwise, return an "unrecognized order code" error message. If protein is equal to the empty string "", return the invalid order" error message. Otherwise, calculate and return the total cost of the order

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions