class student(object):
def student(self):
self.name=input("enter name:")
self.stno=int(input("enter stno:"))
self.score=int(input("enter score:"))
def dis(self):
print("name:",self.name,"stno:",self.stno,"score:",self.score)
def stno(self):
return self.stno
def name(self):
return self.name
def score(self):
return self.score
y=[]
j=0
while(j<3):
a=student()
a.student()
y.append(a)
j+=1
for st in y:
st.dis()
n=int(input("enter #:"))
for c in y:
if c.stno==n:
y.remove(c.stno)
for st in y:
st.dis()
학생 번호와 점수가있는 학생 중 한 명을 학생 번호로 삭제하고 싶습니다. 나는 다음과 같이 씁니다 :이 코드에 대해 remove를 사용하려면 어떻게해야합니까?
n=int(input("enter #:"))
for c in y:
if c.stno==n:
y.remove(c.stno)
분명히 거기에 문제가 있습니다. remove 나 del 또는 pop을 사용하도록 수정할 수 있습니까? pop이나 del은 인덱스가 없으므로 작동하지 않을 수 있다고 생각합니까?
그것은 당신의 동급생과 같습니다 (다른 사람이하지만)이 과제에 대한 질문을한다 : http://stackoverflow.com/q/38352723/189134 – Andy