Question: please show me Part B Part A Start by creating a class called Recipe. Give this class an _init__0 method that allows the user to


please show me Part B
Part A Start by creating a class called Recipe. Give this class an _init__0 method that allows the user to set the title, ingredients, and directions as instance variables. That is, after having defined your class, you should be able to run the following code and receive the printed result. cookies = Recipe("cookies", {"cookie jar" : 1}, ["take a cookie out of the jar"]) print(cookies.title) print(cookies. ingredients) print(cookies.directions) cookies {'cookie jar': 1} ['take a cookie out of the jar'] In [2] : # write class here class Recipe: def_init__(self, title, ingredients, directions): self.title=title self.ingredients=ingredients self.directions=directions In [3]: # test code here cookies = Recipe("cookies", {"cookie jar" : 1}, ["take a cookie out of the jar"]) print(cookies.title) print(cookies. ingredients) print(cookies.directions) cookies {'cookie jar': 1} ['take a cookie out of the jar'] Part B Now add input checking. Modify the _init_0 method to enforce the following conditions: 1. title must be a string. If not, raise an informative TypeError. 2. ingredients must be a dict. If not, raise an informative TypeError. 3. The keys of ingredients must all be strings. If not, raise an informative TypeError. Hint: all( [x == "cookies" for x in container]) will check whether x has value "cookies" for all x in container. You can modify this idea to perform this check without writing a for- loop, although such a loop is also a fine approach. 4. The directions must be a list. If not, raise an informative TypeError. In this and future parts, you can modify your code in Part A -- no need to copy/paste your class. Write a simple test case for each of these four conditions to show that the corresponding error is raised. The first one is written for you. Each of these test cases can be completed in a single line. If you finish early, you can come back and add the following additional checks to your class: 1. The entries of directions must be strings. If not, raise an informative TypeError. 2. The values of ingredients must all be int s or float s. If not, raise an informative TypeError. 3. The values of ingredients must all be nonnegative. If not, raise an informative ValueError. In [ ]: # first test In [ ]: # second test In [ ]: # third test
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
