0

I have a little program written in Python. It is supposed to talk to you like Siri except command line based. It asks you how your day is and when you put good it is supposed to pick 1 out of 5 good responses and say that to you but I keep getting a recursion error here is my code

def nice5():
    print ("Well Thats Good!")
   time.sleep(2)
   randsub(2)

def nice4():
    print ("Great!")
    time.sleep(2)
    randsub()

def nice3():
    print ("Thats Good!")
    time.sleep(2)
    randsub()

def nice2():
    print ("Cool I am glad to hear that!")
    time.sleep(2)
    randsub()

def nice1():
    print ("Thats Good! ")
    time.sleep(2)
    randsub()

def nicerand():
    randnices = [nice1 , nice2 , nice3 , nice4 , nice5]
    randnice = random.choice(randnices)
    nicerand()


def p1checkChoice():
    if choice == "Good":
        nicerand()
    if choice == "good":
       nicerand()
    if choice == "GOOD":
       nicerand()




def greeting():
    clearscr()
    name = input("Hello What is your name: ")
    clearscr()
    print ("Hello " + name)
    time.sleep(2)
    clearscr()
    print ("Allow me to introduce myself")
    time.sleep(2)
    clearscr()
    print ("My name is Chatbot")
    time.sleep(2)
    clearscr()
    choice = input("How has your day been: ")
    global choice
    p1checkChoice()
    greeting()
3
  • Can you provide the exact error message and a definition of Randnices Commented Mar 9, 2016 at 22:39
  • RecursionError: maximum recursion depth exceeded while calling a Python object Commented Mar 9, 2016 at 22:43
  • Global choice with a capital G? Please provide the exact source that you are using. Commented Mar 9, 2016 at 22:56

1 Answer 1

0

There are far too many errors in your sample code to be the actual code you are running; however, the key problem is that checkChoice calls nicerand which calls any of the randnices which call nicerand which calls any of the randnices which call nicerand which calls any of the randnices which calls ....

and eventually you hit the RecursionError.

The fix is simple: do not have any of the randnices functions call back into nicerand; just remove that line from them.

Then they will simply return to nicerand which will return to checkChoice which can continue whatever it is doing.

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.