JkSoftware

Day 16 - coffee_maker.py

Nov 25th, 2021
718
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  10.     def report(self):
  11.         """Prints a report of all resources."""
  12.         print(f"Water: {self.resources['water']}ml")
  13.         print(f"Milk: {self.resources['milk']}ml")
  14.         print(f"Coffee: {self.resources['coffee']}g")
  15.  
  16.     def is_resource_sufficient(self, drink):
  17.         """Returns True when order can be made, False if ingredients are insufficient."""
  18.         can_make = True
  19.         for item in drink.ingredients:
  20.             if drink.ingredients[item] > self.resources[item]:
  21.                 print(f"Sorry there is not enough {item}.")
  22.                 can_make = False
  23.         return can_make
  24.  
  25.     def make_coffee(self, order):
  26.         """Deducts the required ingredients from the resources."""
  27.         for item in order.ingredients:
  28.             self.resources[item] -= order.ingredients[item]
  29.         print(f"Here is your {order.name} . Enjoy!")
  30.  
RAW Paste Data