Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

debug python Background Often, data is stored in a very compact but not human-friendly way. Think of how dishes in a menu can be stored

debug python
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Background Often, data is stored in a very compact but not human-friendly way. Think of how dishes in a menu can be stored in a restaurant database somewhere in the cloud. One way a dish object can be stored is this: "name": "Margherita", "calories": 800, "price": 18.90, "is_vegetarian": "yes", "spicy_level": 2 Obviously, this format is not user-readable, so the restaurant's frontend team produced many lines of code to render and display this content in a way that's more understandable to us, the restaurant users. We have a mini-version of the same task coming up. Given a list of similar complex objects (represented by Python dictionaries), display them in a user-friendly way that we'l define in these instructions. What is a "dish"? In this project, one dish item is a dictionary object that is guaranteed to have the following keys: - "name"; a string that stores the dish's name. - "calories": an integer representing the calorie intake for one serving of the dish. - "price": a float to represent the cost of the dish. - "is_vegetarian"; a string (yeso) to indicate if a dish is vegetarian. - "spicy_level": an integer (eg., from 1 to 4) representing the level of spiciness of the dish. To create a menu that contains all dishes served in a restaurant, we define a list containing dictionaries of dishes information. Here is an example list containing 2 dishes of a restaurant menu that can be used to test our system as we develop it You can add more of your own examples as long as they adhere to the correct formats and types of dictionary values. Your TODO - Create a variable to hold a list of all dictionaries of dish information data at the top of your main program. We will refer to it as restaurant_menu. - Additionally, you need to add a dictionary spicy_sca te_map, which will contain the mapping of the spicy level values, as strings, to their textual interpretation (see example below) spicy_scale map =1 1: "Not spicy", 2: "Low-key spicy", 3: "Hot", 4: "Diabolical", 1 - Define a new function print_restaurant_menu() to display the menu of a restaurant. - Add the implementation based on the documentation provided below. def print_restaurant_menu(restaurant_menu, spicy_scale_map, name_only, show_idx, atart_idx, vegetarian_only): "*" param: restaurant_menu (1ist) - a 11 st object that holds the dictionaries for each dish param: spicy_scale_map (dict) - a dictionary object that is expected to have the integer keys that correspond to the "level of spiciness," paran: name_only (Boolean) If False, then only the name of the dish is printed. otherwlse, displays the tormatted dish intormation, If False, then the index of the menu is not displayed. Otherwise, displays the " {idx+ start_idx . " before the dish name, where idx is the 0-based index in the list. param: start_idx (int) an expected starting value for 1dx that gets displayed for the first dish, if show_idx is True. param: vegetarian_only (str) By default, prints all dishes, regardless of their 1s vegetarian status ("yeso" fleld status). Otherwise, display only the dishes with "is_vegetarian" status set to "yes". returns: None; only prints the restaurant menu A Go through the dishes in the restaurant menu: for ...t - If vegetarian_only is True and the dish is not vegetarian, skip if vegetarian_only and ...: - if the index of the task needs to be displayed (show_idx is True), print dish index only if show_Idx = True: print (.. 1 print the name of the dish - if name_only is False if not name only: print (.. Program Output - I Do not hard-code the provided example values as part of your function-add them to your main program, so that you function can be tested with different dictionaries. 1. Assuming the menu list that's hard-coded above, below is a sample program output. Note the string formatting for the strings like "Price", etc. The function call from the main program: print ("Fu11 menu:") print_restaurant_menu (restaurant_menu_list, spicy_scale_map, name_only = False, show_idx = True, start_idx - 1, vegetarian_only = False) should result in the following output: Ful1 menu: 1. BURRITO - Calories: 500 - Price: $12.90 - Vegetarian? yes - Spicy level: Low-key spicy 2. RICE BOWL. - Calories: 400 - Price: $14.90 - Vegetarian? no - Vegetarian? yes - Spicy level: Low-key spicy 2. RICE BOWL - Calories: 400 * Price: $14.90 - Vegetarian? no - Spicy level: Hot 3. MARGHERITA - Calories: 800 - Price: $18.90 - Vegetarian? no - Spicy level: Low-key spicy 2. Below is another sample program output for listing Vegetarian dishes only. Vegetarian menu: 1. BURRITO - Calories: 500 - Price: $12.90 * Vegetarian? yes * Spicy level: Low-key spicy Troubleshooting / Hints - If you are getting an error SyntaxError: invalid syntax when indexing a dictionary inside an f-string, remember that if the fstring is using double quotations, then the dictionary index should not use them as well. 1.List all items from the menu 0/2 Traceback (most recent call last): Eile "main.py", line 31 , in dish_name - input ("Enter dish name (or ' q ' to quit): ") EOFError: EOF when reading a line Output differs. See highlights below. Special character legend Your output starts with Enter dish name (or ' q ' to quit): Full menu: 1. BURRITOH * Calories: 500 * Price: \$12.90- - Vegetarian? yese * Spicy level: Low-key spicye 2. RICE BOWLH Expected output " Calories: 400H starts with * Price: $14.90% * Vegetarian? now * spicy level: Hot. 3. MARGHERITAN * Calories: 800\% - Price: \$18.904 * Vegetarian? now * Spicy level: Low-key spicy+ Calling the function with a new menu and spice scale (restaurant menu, spicy_scale_map, name_only=True, show_idx=True, 1 . start id =1, vegetarian_only=False) We got the output 1. BURRITO 2. BUDDHA BOWL Test feedback instead of 1. BURRITO 2. BUDDHA BOWL

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

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions