Simulated Coffee Machine with OOP!
Add GIF demo
This commit is contained in:
parent
2cb3f14710
commit
f462cc5ae0
9 changed files with 167 additions and 2 deletions
29
Day 16/oop-coffee-machine/coffee_maker.py
Normal file
29
Day 16/oop-coffee-machine/coffee_maker.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
class CoffeeMaker:
|
||||
"""Models the machine that makes the coffee"""
|
||||
def __init__(self):
|
||||
self.resources = {
|
||||
"water": 300,
|
||||
"milk": 200,
|
||||
"coffee": 100,
|
||||
}
|
||||
|
||||
def report(self):
|
||||
"""Prints a report of all resources."""
|
||||
print(f"Water: {self.resources['water']}ml")
|
||||
print(f"Milk: {self.resources['milk']}ml")
|
||||
print(f"Coffee: {self.resources['coffee']}g")
|
||||
|
||||
def is_resource_sufficient(self, drink):
|
||||
"""Returns True when order can be made, False if ingredients are insufficient."""
|
||||
can_make = True
|
||||
for item in drink.ingredients:
|
||||
if drink.ingredients[item] > self.resources[item]:
|
||||
print(f"Sorry there is not enough {item}.")
|
||||
can_make = False
|
||||
return can_make
|
||||
|
||||
def make_coffee(self, order):
|
||||
"""Deducts the required ingredients from the resources."""
|
||||
for item in order.ingredients:
|
||||
self.resources[item] -= order.ingredients[item]
|
||||
print(f"Here is your {order.name} ☕️. Enjoy!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue