Reputation: 33
I have most of my program done however I keep getting the error and can't seem to figure out why it keeps doing so. I've also tried animal_list = Zoo.Zoo()
line 43, in addAnimal
animal_list = Zoo()
TypeError: 'module' object is not callable
here is some of my program
import Animal
import Zoo
def main():
#set user choice
choice = 0
while choice != "3":
display_menu()
#get user's choice
choice = str(input("What would you like to do? "))
#Perform selected choice
if choice.isalpha():
print("Please enter a numeical value")
elif choice == "1":
addAnimal()
and
#Add animal to list
def addAnimal():
atype = input("What type of animal would you like to create? ")
aname = input("What is the animal's name? ")
theAnimal = Animal.Animal(atype, aname)
theAnimal.set_animal_type(atype)
theAnimal.set_name(aname)
animal_list = Zoo()
animal_list.add_animal(theAnimal,Animal)
Upvotes: 1
Views: 243
Reputation: 4130
From looking at your other questions, your Zoo
class is quite wrong.
Your Zoo
class should be written like this:
class Zoo:
def __init__(self):
self.__animals = []
def add_animal(self, animals):
self.__animals.append(animal)
def show_animals(self):
size = len(self.__animals)
if size == 0:
print("There are no animals in your zoo!")
else:
return __animals
Instead you define methods like this:
def __init__(Animal):
and define variables like:
Animal.__animals = []
which simply don't make sense.
Your problem is that you used a module (Animal
) instead of self
. I have no idea where you might have gotten this idea, but you may want to peruse class definition in the Python documentation.
Upvotes: 2