Define a class Drink
with a method prepare()
. Implement child classes Coffee
and Tea
that override the prepare()
method to print the steps of preparing the respective drinks.
Example 1:
Input: Coffee Output: "Grind coffee beans, brew coffee, pour in cup, add sugar and milk as required"
Example 2:
Input: Tea Output: "Boil water, add tea leaves, brew tea, pour in cup, add sugar and milk as required"
Override the prepare()
method in each subclass to return the respective drink preparation steps.
class Drink: def prepare(self): pass class Coffee(Drink): def prepare(self): return "Grind coffee beans, brew coffee, pour in cup, add sugar and milk as required" class Tea(Drink): def prepare(self): return "Boil water, add tea leaves, brew tea, pour in cup, add sugar and milk as required" # Test the classes coffee = Coffee() print(coffee.prepare()) # Output: Grind coffee beans, brew coffee, pour in cup, add sugar and milk as required tea = Tea() print(tea.prepare()) # Output: Boil water, add tea leaves, brew tea, pour in cup, add sugar and milk as required
Unlock AI & Data Science treasures. Log in!