mardi 21 septembre 2021

Appending a python dictionary From inside an if statement

I'm trying to write a recipe program in Python that accepts user input and appends it to an empty dictionary, but each time I run the code, the dictionary remains empty. Please, what's wrong and what can I do ?

def action():
    answer = input("What would you like to do :- \n"" c.) Create a new recipe \n ""d.) Read all meal recipes \n\n")
    global recipes
    recipes={}
    if answer == "d" :
        print(recipes.values())
    elif answer == "c":
          name =str(input("\nWhat is the name of the food recipe you would like to create ? :- \n"))
          ingredients= str(input('\nWhat are the ingredients required to prepare this meal :- \n'))
          method =str(input('\n How is the meal prepared :- \n'))
          recipes[name]=[name,ingredients,method]
          recipes[name]
action()

Aucun commentaire:

Enregistrer un commentaire