Python Forum
edX "List_o_matic" Program Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
edX "List_o_matic" Program Help
#1
Hello,

I have been setting up my code for the "list_o_matic" program for the Module 2 Required Coding assignment, but for some reason I can't the code I have to run properly. The input prompt appears, but the functions I set up in the loop are not working. I feel like there is an error in syntax or setup that I just haven't noticed, any guidance/help would be appreciated!

Here are the assignment guidelines -----------------------------------------------------

Program: list-o-matic

This program takes string input and checks if that string is in a list of strings

if string is in the list it removes the first instance from list
if string is not in the list the input gets appended to the list
if the string is empty then the last item is popped from the list
if the list becomes empty the program ends
if the user enters "quit" then the program ends
program has 2 parts

program flow which can be modified to ask for a specific type of item. This is the programmers choice. Add a list of fish, trees, books, movies, songs.... your choice.
list-o-matic Function which takes arguments of a string and a list. The function modifies the list and returns a message as seen below.



Here is the code I have --------------------------------------------------------


animals_list = ["cat", "lizard", "dog", "cow"]


def list_o_matic(animal):
    if animal == "":
        animal = animals_list.pop()
        print("1 instance of", animal, "popped from the list")
    elif animal in animals_list:
        return animals_list.remove(animal)
        print("1 instance of", animal, "removed from the list")
    else:
        print("1 instance of", animal, "appended to the list")
        return animals_list.append(animal)
    

while animals_list:
    animal_choice = input("Enter name of an animal, or 'quit' to quit: ")
    if animal_choice.startswith("q"):
        break
    else:
        print("This is the list of animals: ", animals_list)
        
print("Goodbye!") 
Reply
#2
You never call list_o_matic. You need to do that, I would think between lines 20 and 21.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
That fixed it, thanks so much!
Reply


Forum Jump:

User Panel Messages

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