He estado trabajando en esta tarea para la escuela y simplemente no puedo entender por qué no puedo hacer que este programa funcione correctamente. Estoy intentando que el programa permita al usuario ingresar tres animales. Solo me permite ingresar a uno. Sé que tiene que ver con la ubicación de la declaración return en la función make_list, pero no puedo encontrar la manera de solucionarlo.return statement in for bucles
Aquí está mi código:
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 display_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()
Un poco más de detalle ayudaría: El bucle for en make_list() va por completo una vez y luego regresa. En la sangría de pitón es importante. –