Coffee Machine

Ce script fait partie des projets Python de HyperSkill.

j'ai fait toute la formation python de Hyperskill pendant le Confinement 2020.

# Write your code here
class CoffeMachine:
def __init__(self):
# water, milk, beans, cups, money
self.inventory = [400, 540, 120, 9, 550]
# x water, x milk, x beans, cups, price
espresso = (250, 0, 16, 1, 4)
latte = (350, 75, 20, 1, 7)
cappuccino = (200, 100, 12, 1, 6)
self.coffee_list = (espresso, latte, cappuccino)
def menu(self, action):
if action == "buy":
elif action == "fill":
elif action == "take":
elif action == "remaining":
elif action == "exit":
def status(self):
print(f"The coffee machine has:\n"
f"{self.inventory[0]} of water\n"
f"{self.inventory[1]} of milk\n"
f"{self.inventory[2]} of coffee beans\n"
f"{self.inventory[3]} of disposable cups\n"
f"{self.inventory[4]} of money\n")
def fill(self):
texts = ["Write how many ml of water do you want to add:",
"Write how many ml of milk do you want to add:",
"Write how many grams of coffee beans do you want to add:",
"Write how many disposable cups of coffee do you want to add:"]
for i in range(4):
self.inventory[i] += int(input(texts[i]))
def take(self):
print(f"I gave you ${self.inventory[4]}")
self.inventory[4] = 0
def buy(self):
coffee = input("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - return menu:")
if coffee == "back":
proportion = self.coffee_list[int(coffee) - 1]
check = [self.inventory[i] > proportion[i] for i in range(4)]
if all(check):
print("I have enough resources, making you a coffee!")
for i in range(4):
self.inventory[i] -= proportion[i]
self.inventory[4] += proportion[4]
missing = [i for i, x in enumerate(check) if not x]
ressource = ["water", "milk", "beans", "cups"]
for i in missing:
print(f"Sorry, not enough {ressource[i]}!")
coffe_machine = CoffeMachine()
while True:
user_action = input("Write action (buy, fill, take, remaining, exit):")

cyvax - 2023