Estoy tratando de usar un bucle while para agregar objetos a una lista.Usar un bucle para agregar objetos a una lista (python)
Aquí es básicamente lo que quiero hacer:
class x:
pass
choice = raw_input(pick what you want to do)
while(choice!=0):
if(choice==1):
Enter in info for the class:
append object to list (A)
if(choice==2):
print out length of list(A)
if(choice==0):
break
((((other options))))
puedo conseguir el objeto agregado a la lista, pero estoy atascado en cómo agregar varios objetos a la lista en el bucle.
Aquí está el código que tengo hasta ahora:
print "Welcome to the Student Management Program"
class Student:
def __init__ (self, name, age, gender, favclass):
self.name = name
self.age = age
self.gender = gender
self.fac = favclass
choice = int(raw_input("Make a Choice: "))
while (choice !=0):
if (choice==1):
print("STUDENT")
namer = raw_input("Enter Name: ")
ager = raw_input("Enter Age: ")
sexer = raw_input("Enter Sex: ")
faver = raw_input("Enter Fav: ")
elif(choice==2):
print "TESTING LINE"
elif(choice==3):
print(len(a))
guess=int(raw_input("Make a Choice: "))
s = Student(namer, ager, sexer, faver)
a =[];
a.append(s)
raw_input("Press enter to exit")
Cualquier ayuda sería muy apreciada!
todas las variables conjetura llamada debe ser nombrado elección mi error – Will
Aquí puede editar su pregunta;) –
jaja Traté de pero me dio la maldita página de mensaje de error con el LOLcat – Will