我已经完成了我的大部分程序,但我不断得到的错误,似乎无法找出为什么它一直这样做。我也试过animal_list = Zoo.Zoo()
line 43, in addAnimal
animal_list = Zoo()
TypeError: 'module' object is not callable
这是我的一些程序
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()
以及
#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)
从你的其他问题来看,你的
Zoo
课是完全错误的。你知道吗你的
Zoo
类应该这样写:而是定义如下方法:
定义变量如下:
这根本说不通。你知道吗
您的问题是使用了模块(
Animal
)而不是self
。我不知道你是从哪里得到这个想法的,但你可能想细读一下class definition in the Python documentation。你知道吗相关问题 更多 >
编程相关推荐