Jump to content

Requesting Immediate Assistance!

- - - - -

  • Please log in to reply
1 reply to this topic

#1
pythonchallenge

pythonchallenge

    Newbie

  • Members
  • Pip
  • 3 posts
What is wrong with my code, I am having a error saying:

Your program produced too much output! This is probably because of an infinite loop in your code.

I got this error when i submitted this code and it said that it occurred when it was testing a case of unusual capitalization.

The first code is below.



print "Hello, my name is Eliza. What would you like to talk about?"


a = raw_input()

b = a.lower()

c = b.replace(" ","")

d = ''


while c != "goaway":

    if "feel" in b:

        print "Do you often feel that way?"


    elif " you"in b:

        if "me" in b:

            print "What makes you think I "+str(a[b.find("you")+4:b.find("me")-1])+" you?"


    elif "iam" in c:

                for i in a[b.find("i am")+5:]:

                    d = d+i

                    if i == " ":

                        break

                print "How long have you been "+str(d).replace(" ","")+"?"

                d = ''


        

    else:

                print "Please go on"

    a = raw_input()

    b = a.lower()

    c = b.replace(" ","")


 

print "I hope I have helped you!"



The second code is below:




print "Hello, my name is Eliza. What would you like to talk about?"


a = raw_input()

b = a.lower()

c = b.replace(" ","")

d = str()


while b != "go away":

    b = a.lower()

    c = b.replace(" ","")

    d = str()


    if "feel" in b:

        print "Do you often feel that way?"

        a = raw_input()


    elif " you"in b:

        if "you" and "me" in b:

            print "What makes you think I "+str(a[b.find("you")+4:b.find("me")-1])+" you?"

            a = raw_input()

        else:

            a = raw_input()


    elif "iam" in c:

        if "i am" in b or a[0] == "i am":            

                for i in a[b.find("i am")+5:]:

                    d = d+i

                    if i == " ":

                        break

                print "How long have you been "+str(d).replace(" ","")+"?"

                a = raw_input()


        

    elif "feel" and "iam" and "you" not in c:

        if b !="go away":

                print "Please go on"

                a = raw_input()

 

if b =="go away":

    print "I hope I have helped you!"


You can also view the second code by clicking here.
Thanks.

#2
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
I guess that if they were testing unusual capitalization that would mean that the end word might not be "goaway" but, for example "gOaWAy". If so, your while would never stop (condition would never be true since comparison is case sensitive) thus resulting in an infinite cycle. Try doing

while c.lower() != "goaway"





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users