[Tutor] Can anyone help answer this?

Christine Mason masonchristine12 at gmail.com
Tue Jun 9 22:29:11 EDT 2020


Given the following class definition:

 class Food:

     def __init__(self, name, taste):

        self.name
<https://aus01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fself.name%2F&data=02%7C01%7Cchristine.massof%40ird.govt.nz%7C12c2d3472aba4bbc306f08d80ce1e902%7Cfb39e3e923a9404e93a2b42a87d94f35%7C1%7C0%7C637273511711638197&sdata=cM05RAGTtzn%2B1%2BDwU3c6UXadLKFLgyAR5iL2xJGte4g%3D&reserved=0>
= name

        self.taste = taste

 Write a function *createFood()* that takes a list of food items as
argument and creates an instance of class Food for each of them.  It then
returns the list of instances that it has created.

 Each food item in the list that is passed as argument to *createFood() *is
a tuple of the form ('name', 'taste'), so the list of food items might look
like this:

 [('curry', 'spicy'), ('pavlova', 'sweet'), ('chips', 'salty')]

 The function *createFood() *takes the two elements of each tuple and
passes them to the initialiser of Food.  It then collects the objects
returned by the initialiser and adds them to the list that is returned by
createFood().

DO NOT call the function


More information about the Tutor mailing list