Question: python In this lab, you will practice - validating data - constructing objects from validated data Background dish information review We discussed in the previous

python
python In this lab, you will practice - validating data - constructing
objects from validated data Background "dish information" review We discussed in the
previous lab what goes into a dish's information, but it's here too,
for easy reference. In this project, a dish's information is a dictionary
object that is guaranteed to have the following keys: - "name". a

In this lab, you will practice - validating data - constructing objects from validated data Background "dish information" review We discussed in the previous lab what goes into a dish's information, but it's here too, for easy reference. In this project, a dish's information is a dictionary object that is guaranteed to have the following keys: - "name". a string that stores the dishis name. - "ca tories": 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 check if the dish is vegetarian. - "spicy_level": an integer from 1 to 4 representing the level of spiciness of the dish. An example dictionary with a single dish's information could look like: (name": "Margherita", "caloriea" : 800, "prico": 18,90 , "is vegetarian": "no", "spicy_level": 2 Your job is to write a function that takes a list of strings get_new_menu_dish(menu_dish_list, spicy_scate_map) that will create a new dictionary with the structure described above and in the previous lab. For instance, when we pass following arguments to the function: ["Monster Burrito", "800", "16.50", "no", "2"] and {1 : 'not spicy', 2: "mild' \}, the function should return the dictionary \{"name": "Monster Burrito", "catories": 800 , "price": 16.50, "is_vegetarian": "no", "spicy_level": 2} If the length of the list is wrong, return the length of the list. If one particular field is invalid, return a tuple of its name and the value it had However, in addition you must validate the list's elements representing the dish's attributes one at a time before transforming it into a dictionary, ensuring it never crashes regardiess of the input. In order to do this, we ask you to add several functions to the code that validate name, calories, price, spice level, and vegetarian status. The list of functions to implement is as follows. Examples are included for some. - is num Takes in a string and checks if it represents a number (either an integer or a decimal). We will use this function to check if the value entered for the 'price' field is valid or not. - assert is_num(" 6.7)= True - assert is_num("12r9") = False - is_valid_name Takes in the name of a dish and checks whether it is the right length-between 3 and 25 characters, inclusive of both. - is_valid_spicy__evel Takes in a string representing level of spiciness as an int, as well as a dictionary that maps levels of spiciness to their english description, and checks whether the string is a valid level of spiciness according to the dict. - is_valid_is_vegetarian Takes in a string representing whether a dish is vegetarian and checks whether it is either "yes" or "no". - is_valid_calories Takes in a string representing a dishs calories, checks that it corresponds to an integer. - iq_valid_price Takes in a string representing a dish's price, checks whether its a numerical value or not by calling is_num function inside it In each of these, you need to validate both that each of these arguments is a string (or list of strings, depending) and then return a boolean (either True or False) depending on whether the conditions for validity are met. The function checks if "val' is a string; returns False if 'val' is not a string. Otherwise, returns True if the string "val" contains a valid integer or a float. Returns False otherwise. nnn pass def is_valid_name(name_str): param: name_str (string) - a text that is supposed to contain between 3 and 25 characters (inclusive of both) returns: - True if it's a text of the valid length - False, otherwise def is_valid_spicy_level(spicy_level_str, spicy_scale_map): "n" param: spicy_level_str (string) - a string that is expected to contain the level of spiciness param: spicy_scale_map (dict) - a dictionary that contains the mapping between the integer priority value of spiciness to its representation (e.g., key 1 might map to the spiciness value "non spicy") returns: - True if spicy_level_str is a text containing an integer value that maps to a key in the returns: - True if spicy_level_str is a text containing an integer value that maps to a key in the priority_map - False, otherwise pass def is_valid_is_vegetarian(vegetarian_str): wn" param: vegetarian_str (string) - a string that is expected to contain a text "yes" or "no" returns: - True if it's a text with the valid value - False, otherwise pass def is_valid_price(price_str): "" param: price_str (string) - a string that contains a decimal number to represent price returns: - True if it's a text containing decimal number - False, otherwise pass def is_valid_calories(calories_str): param: calories_str (str) - a string that is

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!