Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
abc solution in Clear category for 3 Chefs by Sim0000
from abc import ABCMeta, abstractmethod
class AbstractCook(metaclass=ABCMeta):
def __init__(self):
self.food = self.drink = 0
def add_food(self, food_amount, food_price):
self.food += food_amount * food_price
def add_drink(self, drink_amount, drink_price):
self.drink += drink_amount * drink_price
def total_price(self, food_name, drink_name):
return f'{food_name}: {self.food}, {drink_name}: {self.drink}, Total: {self.food + self.drink}'
@abstractmethod
def total(self):
pass
class JapaneseCook(AbstractCook):
def total(self):
return self.total_price('Sushi', 'Tea')
class RussianCook(AbstractCook):
def total(self):
return self.total_price('Dumplings', 'Compote')
class ItalianCook(AbstractCook):
def total(self):
return self.total_price('Pizza', 'Juice')
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
def json_dict(d):
return dict((k, list(v)) for k, v in d.items())
client_1 = JapaneseCook()
client_1.add_food(2, 30)
client_1.add_drink(2, 10)
client_2 = RussianCook()
client_2.add_food(1, 40)
client_2.add_drink(5, 20)
assert client_1.total() == "Sushi: 60, Tea: 20, Total: 80"
assert client_2.total() == "Dumplings: 40, Compote: 100, Total: 140"
print("Coding complete? Let's try tests!")
June 9, 2018
Comments: