<分区>
我一直在为学校做这个作业,但我只是想不通为什么我不能让这个程序正常工作。我正在尝试让程序允许用户输入三种动物。它只允许我输入一个。我知道这与我在 make_list
函数中放置 return 语句有关,但不知道如何修复它。
这是我的代码:
import pet_class
#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:')
#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
pets = make_list()