Python Forum
Help needed, stuck at the final output - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Help needed, stuck at the final output (/thread-27758.html)



Help needed, stuck at the final output - extricate - Jun-20-2020

Hi,

I've created this code, whereby, if i type "quit", it will return "Goodbye" but in this case, it returns twice. Any hint on how do I make it to return once?

Below is the whole code:

animals = ["cat","goat","cat"]

def list_o_matic(choice):

        if choice in animals:
            animals.remove(choice)
            print(animals)
        elif choice == "":
            animals.pop(0)
            print(animals)
        elif choice != animals:
            animals.append(choice)
            print(animals)



while True:
    if len(animals) < 0:
        print("Goodbye!!")
    else:
        choice = input("Enter animal [cat, goat, cat or others]: ")
        if choice == "quit":
            print("Goodbye!")
            break
        else:
            list_o_matic(choice)
Thanks

Thanks I guess I figured it out