Why we should write object inside or outside the loop?


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):
    def stno(self):
        return self.stno
    def name(self):
        return self.name
    def score(self):
        return self.score

while True:
    c=int(input("enter 1-2))

    if c==1:
    elif c==2:
        for st in y:

I defined above code via using one array.Then I changed that and I want to use 3 arrays for name,student number and score as below:
class student(object):

        def __init__(self):
        def vrod(self):
            self.x.append(input("enter name:"))
            self.z.append(int(input("enter #:")))
            self.y.append(int(input("enter score:")))
        def report(self):
            for self.i in range(len(self.x)):
                print("name:",self.x[self.i],"st number:",self.z[self.i],"score:",self.y[self.i])

while True:
      o=int(input("enter menu:"))
    if o==1:
    elif o==2:

Why should we use a=student() inside the loop in the first one and outside in the second one? If not, it will go wrong. I cannot understand.
Meanwhile, Which of them is common in Python. I mean writing one array or several arrays for working with Python in expert point of view?


oum, what is you want, this is not a lesson in codecademy, right?

if you want to save your student data, you must create an object from class student.
in this class should be save name and personal details.(this is need your mind for how to design class student, get score or no and...)
now you have an student with some details that you want.
now you create a another student with another details.

now in end step, you want to access this student. you can use an array to put this student object into that.

then you must call a cell of array to access to him, or use an dictionary to get these better. this is a solution


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.