coffee_maker.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. class CoffeeMaker:
  2. """Models the machine that makes the coffee"""
  3. def __init__(self):
  4. self.resources = {
  5. "water": 300,
  6. "milk": 200,
  7. "coffee": 100,
  8. }
  9. def report(self):
  10. """Prints a report of all resources."""
  11. print(f"Water: {self.resources['water']}ml")
  12. print(f"Milk: {self.resources['milk']}ml")
  13. print(f"Coffee: {self.resources['coffee']}g")
  14. def is_resource_sufficient(self, drink):
  15. """Returns True when order can be made, False if ingredients are insufficient."""
  16. can_make = True
  17. for item in drink.ingredients:
  18. if drink.ingredients[item] > self.resources[item]:
  19. print(f"Sorry there is not enough {item}.")
  20. can_make = False
  21. return can_make
  22. def make_coffee(self, order):
  23. """Deducts the required ingredients from the resources."""
  24. for item in order.ingredients:
  25. self.resources[item] -= order.ingredients[item]
  26. print(f"Here is your {order.name} ☕️. Enjoy!")