How can I move the "cost" argument from inside of 'MENU' to a separate python file?
Question:
drink = input("Would you like to buy a espresso, latte or cappuccino?:n").lower()
if drink == "espresso":
print(MENU["cost"])
I am getting this error when I try to input something. Can anyone help?
File "C:UsersjoecaUdemyGamesDay10Coffee Machine.py", line 25, in purchase
print(MENU["cost"])
KeyError: ‘cost’
I was hoping that I could move this ‘cost’ argument to a separate file in order for it to be easily viewed and altered.
Answers:
this MENU["cost"]
mean that MENU
is a dictionary and you try to get value of 'cost'
key from that dictionary
the error shows you that in dictionary MENU
there is no such key/value pair with the 'cost'
key
In general, you would do it this way:
from othermodule import othervariable
drink = input("...").lower()
if drink == "espresso":
print(MENU[othervariable])
drink = input("Would you like to buy a espresso, latte or cappuccino?:n").lower()
if drink == "espresso":
print(MENU["cost"])
I am getting this error when I try to input something. Can anyone help?
File "C:UsersjoecaUdemyGamesDay10Coffee Machine.py", line 25, in purchase
print(MENU["cost"])
KeyError: ‘cost’
I was hoping that I could move this ‘cost’ argument to a separate file in order for it to be easily viewed and altered.
this MENU["cost"]
mean that MENU
is a dictionary and you try to get value of 'cost'
key from that dictionary
the error shows you that in dictionary MENU
there is no such key/value pair with the 'cost'
key
In general, you would do it this way:
from othermodule import othervariable
drink = input("...").lower()
if drink == "espresso":
print(MENU[othervariable])