Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clean and documented. solution in Clear category for 3 Chefs by Celshade
class AbstractCook(object):
"""Establish a base class which produces various types of chefs.
Each child of AbstractCook() will specialize in a specific dish and drink.
Public Attributes:
food (str): The type of food served.
drink (str): The type of drink served.
order (list): A list of the client's total food and drink prices.
Public Methods:
add_food(): Add food to the client's order.
add_drink(): Add drinks to the client's order.
total(): Calculate the total order.
"""
def __init__(self) -> None:
self.food, self.drink = str, str
self.order = [0, 0]
def add_food(self, quantity: int, price: int) -> None:
"""Add food to the order.
Args:
quantity: The amount of food to be added.
price: The price per dish.
"""
self.order[0] += (quantity * price)
def add_drink(self, quantity: int, price: int) -> None:
"""Add drinks to the order.
Args:
quantity: The amount of drinks to be added.
price: The price per drink.
"""
self.order[1] += (quantity * price)
def total(self) -> str:
"""Return the total order and price breakdown."""
food = f"{self.food}: {self.order[0]}"
drink = f"{self.drink}: {self.order[1]}"
total = f"Total: {sum(self.order)}"
return f"{food}, {drink}, {total}"
class JapaneseCook(AbstractCook):
"""Establish a chef that specializes in Japanese cuisine.
Extend the attributes and methods of AbstractCook().
"""
def __init__(self) -> None:
super().__init__()
self.food, self.drink = "Sushi", "Tea"
class RussianCook(AbstractCook):
"""Establish a chef that specializes in Russian cuisine.
Extend the attributes and methods of AbstractCook().
"""
def __init__(self) -> None:
super().__init__()
self.food, self.drink = "Dumplings", "Compote"
class ItalianCook(AbstractCook):
"""Establish a chef that specializes in Italian cuisine.
Extend the attributes and methods of AbstractCook().
"""
def __init__(self) -> None:
super().__init__()
self.food, self.drink = "Pizza", "Juice"
March 21, 2019