Untitled
unknown
python
3 years ago
3.7 kB
5
Indexable
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,
"profit": 0,
}
def check_if_enough_money(choice, inserted_amount):
coffee_cost = MENU[choice]['cost']
if inserted_amount == coffee_cost or inserted_amount > coffee_cost:
return True
else:
return False
def check_if_enough_resources(users_choice):
if users_choice in ['latte', 'cappuccino']:
if resources['water'] > MENU[users_choice]['ingredients']['water']:
return True
elif resources['milk'] > MENU[users_choice]['ingredients']['milk']:
return True
elif resources['coffee'] > MENU[users_choice]['ingredients']['coffee']:
return True
else:
return False
elif users_choice == 'espresso':
if resources['water'] > MENU[users_choice]['ingredients']['water']:
return True
elif resources['coffee'] > MENU[users_choice]['ingredients']['coffee']:
return True
else:
return False
def count_change(inserted_amount, users_choice):
change = inserted_amount - MENU[users_choice]['cost']
return change
def show_report():
print(f"Water: {resources['water']}ml\n"
f"Milk: {resources['milk']}ml\n"
f"Coffee: {resources['coffee']}g\n"
f"Money: ${resources['profit']}"
)
def update_resources(users_choice):
resources['water'] = resources['water'] - MENU[users_choice]['ingredients']['water']
resources['coffee'] = resources['coffee'] - MENU[users_choice]['ingredients']['coffee']
if users_choice != 'espresso':
resources['milk'] = resources['milk'] - MENU[users_choice]['ingredients']['milk']
return
def update_profit(users_choice):
resources['profit'] += MENU[users_choice]['cost']
return
def coffee_machine():
users_choice = input("What would you like? (espresso/latte/cappuccino): ").lower()
if users_choice in ['espresso', 'latte', 'cappuccino']:
if check_if_enough_resources(users_choice) == True:
print("Please insert coins.")
quarters = int(input("How many quarters?: "))
dimes = int(input("How many dimes?: "))
nickel = int(input("How many nickels?: "))
pennies = int(input("How many pennies?: "))
inserted_amount = quarters * 0.25 + dimes * 0.1 + nickel * 0.05 + pennies * 0.01
is_enough = check_if_enough_money(users_choice, inserted_amount)
if is_enough == True:
change = round(count_change(inserted_amount, users_choice), 2)
update_resources(users_choice)
update_profit(users_choice)
print(f"Here is ${change} in change.")
print(f"Here is your {users_choice}. Enjoy!")
coffee_machine()
else:
print("Sorry that's not enough money. Money refunded.")
coffee_machine()
else:
print("Not enough resources.")
coffee_machine()
elif users_choice == 'report':
show_report()
coffee_machine()
elif users_choice == 'off':
exit()
coffee_machine()Editor is loading...