Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for 3 Chefs by oduvan
class AbstractCook:
foods = 0
drinks = 0
food_name = 'Food'
drink_name = 'Drink'
def add_food(self, amount, price):
self.foods += amount * price
def add_drink(self, amount, price):
self.drinks += amount * price
def total(self):
return '{fn}: {fa}, {dn}: {da}, Total: {t}'.format(
fn=self.food_name,
fa=self.foods,
dn=self.drink_name,
da=self.drinks,
t=self.drinks + self.foods
)
class JapaneseCook(AbstractCook):
food_name = 'Sushi'
drink_name = 'Tea'
class RussianCook(AbstractCook):
food_name = 'Dumplings'
drink_name = 'Compote'
class ItalianCook(AbstractCook):
food_name = 'Pizza'
drink_name = '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_drink(2, 10)
client_2 = RussianCook()
client_2.add_food(1, 40)
client_2.add_drink(5, 20)
client_3 = ItalianCook()
client_3.add_food(2, 20)
client_3.add_drink(2, 10)
assert client_1.total() == "Sushi: 60, Tea: 20, Total: 80"
assert client_2.total() == "Dumplings: 40, Compote: 100, Total: 140"
assert client_3.total() == "Pizza: 40, Juice: 20, Total: 60"
print("Coding complete? Let's try tests!")
June 18, 2018
Comments: