Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First_of_3 Chefs solution in Speedy category for 3 Chefs by Oleg_Novikov
class AbstractCook:
def __init__(self):
self._food = 0
self._drink = 0
self._total = 0
def add_food(self, qty, price):
self._food += qty * price
def add_drink(self, qty, price):
self._drink += qty * price
def _total_string(self, food_name, drink_name):
self._total += self._drink
self._total += self._food
return f"{food_name}: {self._food}, {drink_name}: {self._drink}, Total: {self._total}"
class JapaneseCook(AbstractCook):
def total(self):
return self._total_string('Sushi', 'Tea')
class RussianCook(AbstractCook):
def total(self):
return self._total_string('Dumplings', 'Compote')
class ItalianCook(AbstractCook):
def total(self):
return self._total_string('Pizza', 'Juice')
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
client_1 = JapaneseCook()
client_1.add_food(2, 30)
client_1.add_food(3, 15)
client_1.add_drink(2, 10)
client_2 = RussianCook()
client_2.add_food(1, 40)
client_2.add_food(2, 25)
client_2.add_drink(5, 20)
client_3 = ItalianCook()
client_3.add_food(2, 20)
client_3.add_food(2, 30)
client_3.add_drink(2, 10)
assert client_1.total() == "Sushi: 105, Tea: 20, Total: 125"
assert client_2.total() == "Dumplings: 90, Compote: 100, Total: 190"
assert client_3.total() == "Pizza: 100, Juice: 20, Total: 120"
print("Coding complete? Let's try tests!")
Oct. 22, 2019