Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python strictly follow the rules plz:)) In this lab, you will practice: - storing and retrieving data from lists and dictionaries - displaying data in

python
strictly follow the rules plz:))
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
In this lab, you will practice: - storing and retrieving data from lists and dictionaries - displaying data in a user-friendly way - use str.upper() - use f-strings for price formatting 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", "calorlea": 800, "price": 18.90, "1s vegetarian": "yen", "ppicy_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 min-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 well 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 le_map, which will contain the mapping of the spicy level values, as strings, to their textual interpretation (see example below) spicy_scale map - I 1: "Not splcy", 2: "Low-key spicy", 3: "Hot", 4: "Diabolical", - 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 irestaurant_menu, spicy_scale_map, namo_oniy, thow_idx, start_idx, vegetarian_on 1y1 : "" param: reotaurant menu (1iat) - a liot object that holds the diettonaries for each diah param: spicy_scale map (dict) - a dletionary object that is expected to have the integer keya that correspond to the "level of apicineas." params name_only (Boolean) If False, then only the name of the dish is printed. Otherulie, display the formacted di oh information. Otherwige, displays the formatied dish information. param: show idx (Boolean) If False, then the index of the menu is not displayed. Otherwise, displays the " (1dx+ atart 1dx)." before the dish name, where 1dx is the 0 -based index in the list. paramt start idx (int) an expected starting value for 1dx that gets displayed for the flrat dish, if show fdx is True. paran: vegetarian only (str) By default, prints all diahes, regardless of their 15 vegetarian status ("yeso" fteld status). otherwise, display only the dishes with "is vegetarian" statua set to "yes". returns: None; only prints the restaurant menu "u* * So through the dishes in the restaurant menu: for i 1. if vegetarian only is True and the dish is not vegetarian, skip if vegetarian only and .... 1 if the index of the tark needs to be displayed (show ld 15 True), print diah index only it ahom idx whe True: print() + print the nathe of the dish 1 If namie_oniy is Falie if not name_onlyz print () Program Output - A. 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 thats 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("Eul1 nenu:") print_rostaurant_monu(restaurant_menu_1ist, sploy_scale_map, nane_only - False, show_idx = True, start_idx - 1, vegetarian_only = False) should result in the following output Pull menus 1. WT - Calories: 500 - Prtcer 512.90 - yegetarian? yea - spicy loveli bow-koy aploy 2. Mrce nowL - Caloclees 400 - Prices 514.90 - Vegetarianz no 2. RICE BOWI. - Calories: 400 * Price: $14.90 - Vegetarian? no - Spicy level: Hot 3. MARGHERITA - Caloriest 800 - Price: $18.90 - Vegetarian? no - Sploy levela Low-key spicy 2. Below is another sample program output for listing Vegetarian dishes only. Vegetarian menu: 1. BURRITO - Calortes: 500 - Price: $12.90 - Vegotarianz yes - spicy level: Low-key spley Troubleshooting / Hints - If you are getting an error SyntaxError: invalid syntax when indexing a dictionary inside an fstring, remember that if the f. string is using double quotations, then the dictionary index should not use them as well

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions