Python Forum
Help needed, stuck at the final output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed, stuck at the final output
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Smile Final Projet - Credit Risk Rauchvant 3 2,446 Nov-18-2020, 03:21 PM
Last Post: Rauchvant
  Final Project (Databases, GUI, and Classes) poochenthecreator 1 1,652 Apr-27-2020, 09:58 PM
Last Post: deanhystad
  Final Project Help hyg71886 6 3,983 Feb-07-2019, 01:30 AM
Last Post: micseydel
  Trouble with edX Python Final sarah_mb_sues 11 13,772 Jun-19-2018, 10:36 AM
Last Post: cryomick
  Final problem Truman 4 4,034 Jan-22-2018, 11:42 PM
Last Post: Truman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020