Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
27-liner: let's metacook solution in Creative category for 3 Chefs by przemyslaw.daniel
class MetaCook(type):
def __new__(cls, name, bases, attrs, **options):
attrs['food_name'] = options['food_name']
attrs['drink_name'] = options['drink_name']
return type.__new__(cls, name, bases, attrs)
def __init__(cls, name, bases, attrs, **options):
pass
class BaseCook:
def __init__(self):
self.food = self.drink = 0
def add_food(self, amount, price):
self.food += amount*price
def add_drink(self, amount, price):
self.drink += amount*price
def total(self):
data = self.food_name, self.food, self.drink_name, self.drink, self.food + self.drink
return "%s: %s, %s: %s, Total: %s" % data
class JapaneseCook(BaseCook, metaclass=MetaCook, food_name='Sushi', drink_name='Tea'):
pass
class RussianCook(BaseCook, metaclass=MetaCook, food_name='Dumplings', drink_name='Compote'):
pass
class ItalianCook(BaseCook, metaclass=MetaCook, food_name='Pizza', drink_name='Juice'):
pass
June 21, 2018