Python 为什么我得到一个列表未定义的错误?

Python 为什么我得到一个列表未定义的错误?,python,list,python-3.x,nameerror,Python,List,Python 3.x,Nameerror,我一直收到一个错误: 名称错误:未为第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)

我一直收到一个错误:

名称错误:未为第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()

您没有传递
动物
,但是
动物列表
,更改为此,应该可以:

def main():
    animals = make_list()
    print("Here is the data you entered:", display_list(animals))
由于
animal_list
make_list
功能范围内,您在
main()
功能范围内无权访问此名称


当您从
make\u list
返回
animal\u list
并将
animals
分配给结果时,您应该直接将其传递给
display\u list

@helpplease,lol不用担心偶尔会发生在每个人身上。为了以防万一,我还解释了为什么不能在另一个函数中访问这些名称