0

I am making a basic recipe viewer of which i have yet to finish , a problem i have is that when i append my recipe to a list and print each list this error appears in the Python shell; the bold represent the users input

Welcome to Mohamed Ismail's Recipe Viewer

Add Recipe (add), Load Recipe (load) or Delete Recipe (delete)

add

Input recipe id = 1

Input recipe name = Cake

Summary


Recipe id = 1

Recipe for Cake

Save Recipe?

Yes

...

Saved Succesfully

Add Recipe (add), Load Recipe (load) or Delete Recipe (delete)

load

Here are your existing recipe id's

Loading...

['1']

Select Recipe by id 1

[('Recipe id =', '1')]

[<function function.<locals>.fileb at 0x105920400>] # this is the error

Go back? or exit


This is my code , please help with this problem it would be much appreciated

import time

currentrecipes = []
rp1 = []
rp2 = []


print("Welcome to Mohamed Ismail's Recipe Viewer")
time.sleep(1)

def function():
     print('Add Recipe (add), Load Recipe (load) or Delete Recipe (delete)')
     choice = input()
     if choice == 'add':
            a = input('Input recipe id = ')
            b = input('Input recipe name = ')
            filea = ("Recipe id =",a)
            fileb = ("Recipe for =",b)
            print('')
            print("Summary")
            print("------------------")
            file1 = print("Recipe id =",a)
            file2 = print("Recipe for",b)

            def file():
                return filea
            def fileb():
                return fileb
            file()
            fileb()
            print('Save Recipe?')
            userinput = input()
            if userinput == 'Yes':
                 if a == '1':
                    currentrecipes.append(a)
                    rp1.append(file())
                    rp2.append(fileb())
                    print('...')
                    time.sleep(0.5)
                    print("Saved Sucesfully")
                    function()
                 else:
                      print("Choose a recipe id of 1")
                      print("Going back...")
                      time.sleep(2)
                      function()
            else:
                 function()
     elif choice == 'load':
          if currentrecipes == []:
             print("Error 619: You have no current recipes")
             function()
          else:
             print("Here are your existing recipe id's")
             print("Loading...")
             time.sleep(2)
             print(currentrecipes)
             option = input("Select Recipe by id ")
             if option == '1':
                 print(rp1)
                 print(rp2)
                 userchoice = input("Go back? or exit ")
                 if userchoice == 'Go back':
                     function()
                 else:
                      exit()    


     elif choice == 'delete':
          if currentrecipes == []:
             print("Error 619: You have no current recipes")
             function()
          else:

              print("Here are your existing recipe id's")
              print("Loading...")
              time.sleep(2)
              print(currentrecipes)
              option = input("Which recipe do you wish to delete ")
              if option == '1':
                   if '1' not in currentrecipes:
                       print("Error 404: Recipe is not in saved recipes")
                       function()
                   else:
                       currentrecipes.remove('1')
                       print('Loading...')
                       time.sleep(1)
                       print(currentrecipes)
                       time.sleep(0.5)
                       print("Deleted Succesfully")

     else:
          print("Please select one of the 3 options")
          time.sleep(1)
          function()

function()
1
  • What is the expected output? Commented Apr 26, 2015 at 19:25

1 Answer 1

0

Assuming you expect the output to be [('Recipe for =', 'Cake')] the problem occurs when you define the function fileb using the same name as the tuple. So, fileb() now returns a function versus the tuple you want returned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.