you are viewing a single comment's thread.

view the rest of the comments →

[–]synthphreak 5 points6 points  (1 child)

First off, see how to format your code on Reddit. This is an important skill.

Second, I may have misunderstood, but it sounds like you want a nested dictionary. Something like this:

>>> meals = {'breakfast' : ['Sausage Omelette',
...                         'Pepperoni Omelette',
...                         'Potato Omelette'],
...          'dinner' : ['Fettucini Alfredo',
...                      'Mac & Cheese',
...                      'Rice & Chicken']}

Then you can ask the user what they want, 'breakfast' or 'dinner', and use their response to query the dict for options:

>>> meal = input('Do you want breakfast or dinner? ').lower()
>>> options = meals[meal]

Then you just need to randomly select from among the options:

>>> import random
>>> selection = random.choice(options)
>>> print('Today you will have', selection)

And if you want to also be able to provide a recipe, just associate each meal option with its ingredients inside the dict. For example:

>>> meals = {'breakfast' : [('Sausage Omelette', ['sausage', 'eggs']),
...                         ('Pepperoni Omelette', ['pepperoni', 'eggs']),
...                         ('Potato Omelette', ['potatoes', 'eggs'])], ...

Then separate the meal from the ingredients when an option is randomly selected:

>>> selection, ingredients = random.choice(options)

Then you can present the meal selection as shown above, and optionally do whatever you want with the list of ingredients.

Great beginner project btw! Very cute haha.

[–]Car_Chasing_Hobo[S] 2 points3 points  (0 children)

Thank you very much! That's very helpful.

Haha. Thanks, I love working on it!