I attempted to do the exercise that was given in the example, the about about getting food out of the refrigerator and cooking it, but my code does not work:
class Refrigerator:
cooling = True
class Microwave:
working = True
def cook(self, food):
return ["cooked "+item for item in food]
def get_food_from_fridge(food = []):
if Refrigerator.cooling == False: raise RefrigeratorException
else: return food
def heat_food(food):
if Microwave.working == False: raise MicrowaveException
else: return Microwave.cook(food)
try:
food = get_food_from_fridge(["carrots", "potato"])
food = heat_food(food)
print(food)
except KitchenException:
food = order_takeout()
The above code raises the following TypeError:
TypeError: cook() missing 1 required positional argument: 'food'
I do not understand why? Could someone explain?