I need to subtract the ingredients from a coffee (user choice = espresso, latte, cappuccino), which are given in a dictionary, from the base resources that the coffee machine holds (water, coffee, milk). Those resources are given in another dictionary. How can I subtract them from each other, after the user has chosen which coffee to go for?
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,
}
From previous lessons, I learned that I need to format the data from the dictionary so that it becomes usable in the code. But I’m at a very beginner level and I’m stuck after formatting the data.
def format_data(choice):
"""Format ingredients into printable format: water, milk, coffee, cost"""
water = MENU[user_choice]['ingredients']["water"]
milk = MENU[user_choice]['ingredients']["milk"]
coffee = MENU[user_choice]['ingredients']["coffee"]
cost = MENU[user_choice]['ingredients']["cost"]
user_choice = input("What would you like? (espresso/latte/cappuccino").lower()
gringocoder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.