MENU = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
},
"cost": 1.5,
},
"latte": {
"ingredients": {
"water": 200,
"milk": 150,
"coffee": 24,
},
"cost": 2.5,
},
"cappuccino": {
"ingredients": {
"water": 250,
"milk": 100,
"coffee": 24,
},
"cost": 3.0,
}
}
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
money = 0
def money_count():
print("please insert coins")
quarters = int(input("How many quarters?"))
dimes = int(input("How many dimes?"))
nickles = int(input("How many nickles?"))
pennies = int(input("How many pennies?"))
return quarters*0.25+dimes*0.1 +nickles*0.05+pennies*0.01
def check_remain(resource_left, drink_for_make):
milk = True
water = True
coffee = True
if resource_left['water']<MENU[drink_for_make]['ingredients']['water']:
water= False
print("Sorry there is not enough water")
if 'milk' in MENU[drink_for_make]['ingredients'] and resource_left['milk']<MENU[drink_for_make]['ingredients']['milk']:
milk = False
print("Sorry there is not enough milk")
if resource_left['coffee']<MENU[drink_for_make]['ingredients']['coffee']:
coffee = False
print("Sorry there is not enough coffee")
if water == False or milk == False or coffee == False:
return False
def using_material(resource_left, drink_for_make):
resource_left['water']-=MENU[drink_for_make]['ingredients']['water']
resource_left['coffee'] -= MENU[drink_for_make]['ingredients']['coffee']
if 'milk' in MENU[drink_for_make]['ingredients']:
resource_left['milk'] -= MENU[drink_for_make]['ingredients']['milk']
def report():
print(f"Water: {resources['water']}ml")
print(f"Milk: {resources['milk']}ml")
print(f"Coffee:{resources['coffee']}ml")
print(f"Money:${money}")
machine_on = True
while machine_on:
prompt = input("What would you like? (espresso/latte/cappuccino):")
if prompt =="off":
break
elif prompt =="report":
report()
elif prompt =='espresso' or prompt =="latte" or prompt =="cappuccino":
remain = check_remain(resources,prompt)
if remain ==False:
continue
else:
gave = money_count()
if gave > MENU[prompt]['cost']:
print(f"Here is ${round(gave-MENU[prompt]['cost'],2)} in change")
print(f"Here is your {prompt}☕️, Enjoy!")
money+=MENU[prompt]['cost']
using_material(resources,prompt)
Redd Wu
My life with communication and coding