【发布时间】:2015-04-20 02:12:36
【问题描述】:
我不断收到错误:
NameError: name 'animal_list' 没有为第 4 行定义
我浏览了我的代码,但似乎无法弄清楚原因。谢谢你的帮助!
import Animal
def main():
animals = make_list()
print("Here is the data you entered:", display_list(animal_list))
def make_list():
animal_list = []
run = True
while(run):
atype = input("What type of animal would you like to create? ")
aname = input("What is the animals name? ")
alist = Animal.Animal(atype, aname)
animal_list.append(alist)
another = input("Would you like to add more animals (y/n)? ")
if (another !="y"):
run = False
return animal_list
def display_list(animal_list):
print("Animal List")
print("------------")
print()
for item in animal_list:
print(item.get_name(), "the", item.get_animal_type(), "is")
main()
【问题讨论】:
标签: python list python-3.x nameerror