I am not particularly a beginner on Python but i'm not too experienced either.
I am working on a small project and am wondering what is the best course of action. I want to make a food dictionary of different frozen foods that display the nutritional value of each entry.
An example for an entry in Food_Catalog_Frozen.py would be:
Burrito = {
"calories": 310,
"fats": 14,
"sodium": 330,
"carbohydrates": 35,
"sugars": 1,
"protein": 9,
}
Then I would like to make a separate "What's cookin'?" script where a user inputs everything they ate and all the values would be added.
Before dealing with any analytics I wanted to see if I could print out the foods as they are. The following is the code to try print out the nutritional information for the burrito above.
import Food_Catalog_Frozen as Frozen
print("What's cookin', good lookin'?\n")
STOP = False
while STOP == False:
food = input() # Enter Burrito
if food == "done":
STOP = True
else:
print(Frozen.food)
And the following error is thrown:
print(Frozen.food)
AttributeError: module 'Food_Catalog_Frozen' has no attribute 'food'
The major problem is the variable food, although in this instance now valued as Burrito, the dictionary is still searching for Frozen.food instead of Frozen.Burrito which does work. It appears that it is not possible to search dictionaries through user input.
If anyone could say why this is not working or if there is a better way to do this that would be greatly appreciated. Thank you.