-1

Hi I am working on a program to store some files to a text document that can be reloaded when necessary. Below is the beginning of the code however when run I receive a trace back error stating "recipe_title is not defined" when I thought I had defined it as the name of the text file. Please help show me what I have done wrong.

import sys

opt=0

def choice1():
    print("WORKED")
def choice2():
    Recipe_Name = input("Please enter a recipe name: ")
    Recipe_List = open(recipe_title.txt,"w")
    Recipe_List.write(recipe_title+"\n")

def ingredient_input_loop(recipe_title, ):
        Recipefile = open(recipe_title,"w")
        if(ingredient== "end" or "End" or "END" or "EnD" or "eNd" or "enD" or "ENd" or "eND"):
            Recipe.write(recipe_title)

1 Answers1

1

recipe_title.txt is your file name and not a variable. Therefore you should add quotes

Recipe_List = open('recipe_title.txt',"w")

or if the recipe_title is really a variable:

Recipe_List = open('{}.txt'.format(recipe_title),"w") # now you can open brocolli.txt for example

General feedback about your code:

  • Variable names should not have Uppercase characters. This should only be used for Class names.
  • Checking if for all the combinations of 'end' can be written to if ingredient.lower() == "end":
RvdK
  • 19,580
  • 4
  • 64
  • 107