2011-04-27 77 views
0

我继续尝试第二运行这个程序,但不断收到此错误:名没有定义的错误

Traceback (most recent call last): 
    File "C:\Users\bwhite3500\Documents\School\Spring 2011\CITP 110 - Intro to Computer Programming\pet_list.py", line 57, in <module> 
    main() 
    File "C:\Users\bwhite3500\Documents\School\Spring 2011\CITP 110 - Intro to Computer Programming\pet_list.py", line 15, in main 
    display_list(pets) 
NameError: global name 'display_list' is not defined* 

这里是我的代码:

import pet_class 

def main(): 
    #get list of pet objects 
    pets = make_list() 

    #Display the data in a list. 
    print 'Here is the data you entered:' 
    display_list(pets) 


#The make_list function gets data from the user for three pets. The function 
# returns a list of pet objects containing the data. 

def make_list(): 
    #create empty list. 
    pet_list = [] 

    #Add three pet objects to the list. 
    print 'Enter data for three pets.' 
    for count in range (1, 4): 
     #get the pet data. 
     print 'Pet number ' + str(count) + ':' 
     name = raw_input('Enter the pet name:') 
     animal=raw_input('Enter the pet animal type:') 
     age=raw_input('Enter the pet age:') 
     print 

     #create a new pet object in memory and assign it 
     #to the pet variable 

     pet = pet_class.PetName(name,animal,age) 

     #Add the object to the list. 
     pet_list.append(pet) 

    #Return the list 
     return pet_list 

#The display_list function accepts a list containing pet objects 
#as an argument and displays the data stored in each object. 

def diplay_list(pet_list): 
    for item in pet_list: 
     print item.get_name() 
     print item.get_animal_type() 
     print item.get_age() 
     print 

#call main function 
main() 

我是新来这一点,很迷茫。请帮助

回答

1

你打电话给你的功能diplay_list,而不是display_list

+0

哇,那里有2小时我的生活我永远不会回来了!谢谢您的帮助。 – 2011-04-27 21:32:23

2

检查拼写:

def diplay_list(pet_list): 
相关问题