Question: (b) (8 marks) Define a function that takes a menu comprising three dishes, and a specified ingredient, and outputs true if all the dishes on
(b) (8 marks)
Define a function that takes a menu comprising three dishes, and a specified ingredient, and outputs true if all the dishes on the menu are free from the specified ingredient. If any of the dishes on the menu contain the specified ingredient, the function outputs false.
A menu is represented as a list of three dishes.
A dish is represented as a non-empty list of non-empty strings, the first string being the name of the dish and the remaining strings being the ingredients of the dish.
A dish can have a name but no listed ingredients. Ingredients can be duplicated. If the name of the dish matches the specified ingredient, the function should output false.
For example, the menu:
| Dish | Ingredients |
|---|---|
| soup | onion, potato, leek, celery |
| pizza | bread, tomato, cheese, cheese |
| banana |
would be represented in Python as:
menu = [ ['soup','onion','potato','leek','celery'], ['pizza','bread','tomato','cheese','cheese'], ['banana'] ]
This example menu is not free from banana.
Function: free from ingredient Inputs: Preconditions: Output: Postconditions:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
