while 루프를 사용하여 목록에 개체를 추가하려고합니다.루프를 사용하여 목록에 개체 추가 (파이썬)
여기에 내가하고 싶은 것을 기본적이다 :
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))))
내가 개체가 목록에 추가 얻을 수 있습니다,하지만 난 루프에서 목록에 여러 개체를 추가하는 방법에 붙어있다.
이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")
이 어떤 도움을 크게 감상 할 수있다 : 여기
내가 지금까지 가지고있는 코드입니다!while choice != 0:
...
a = []
a.append(s)
는 한 번만 실행되도록 루프 위의 초기화를 옮겨보십시오 :
모든 변수가 내 실수 – Will
당신은 당신의 질문을 편집 할 수 있습니다) –
하하 난하려하지만 난 있어요 LOLcat – Will