Hey, You need to use std.append(STUDENT(roll,name,present,absent))
Since you have just initialized the list named std, there is no index available in the begining. Thanks, Prince On Sun, 19 Aug 2018, 16:00 Sayantan, <skb655...@gmail.com> wrote: > Hello Ankur, > > A few things before we take the program in context: > > 1. Always paste the code in a page(pastebin/paste.ubuntu.com & the like) > so that the indentation remains proper. This will help the members to > easily figure out the issue with the code. > > 2. Always refer to the error message provided by the interpreter before > you approach an audience. You, may have in this case, already done that. > This is just a suggestion. > > Now, back to the code, the error is because there is no > definition/information about 'std' in the code. The interpreter doesn't > know in this case the type of 'std' itself. As a result, when you are > trying to push a value into the std[i] variable/memory(a collection is > what you have in mind), the interpreter is spewing this error message. > > Defining std = [] or the specific collection type(dict/tuple) would > resolve this error. > > -- > Sayantan Bhattacharya > [Sent from pine@dev-machine] > > On Sun, 19 Aug 2018, ankur gupta wrote: > > > ---------- Forwarded message --------- > > From: ankur gupta <ankurim...@gmail.com> > > Date: Sun, Aug 19, 2018 at 3:07 PM > > Subject: Please help with this code > > To: <bangpypers@python.org> > > > > > > Dear Sir > > I am new to python programing, I am getting error while executing this > > code. I want to generate multiple instance using while loop to store data > > following is the code > > > > class STUDENT: > > no_of_students=0 > > def __init__(self,roll,name,present,absent): > > self.roll=roll > > self.name=name > > self.present=present > > self.absent=absent > > STUDENT.no_of_students+=1 > > > > n='Y' > > i=0 > > while n=='Y' or n=='y': > > roll=input("ENTER NAME: ") > > name=input("ENTER ROLL NO:") > > present=input("ENTER NO. OF DAYS PRESENT:") > > absent=input("ENTER NO. OF DAYS ABSENT:") > > std[i] = STUDENT(roll,name,present,absent) > > n=input("ENTER MORE RECORDS (Y/y)?...") > > i+1 > > > > > > GETTING THIS ERROR > > > > ankur@ankur-Lenovo-G50-80:~/PycharmProjects$ cd > /home/ankur/PycharmProjects > > ; env "PYTHONIOENCODING=UTF-8" "PYTHO > > NUNBUFFERED=1" /home/ankur/anaconda3/bin/python > > /home/ankur/.vscode/extensions/ms-python.python-2018.4.0/pythonFi > > les/PythonTools/visualstudio_py_launcher.py /home/ankur/PycharmProjects > > 42323 34806ad9-833a-4524-8cd6-18ca4aa74f1 > > 4 RedirectOutput,RedirectOutput "/home/ankur/PycharmProjects/STUDENTS > > ATTENDANCE.PY" > > ENTER NAME: ANKUR > > ENTER ROLL NO:1 > > ENTER NO. OF DAYS PRESENT:12 > > ENTER NO. OF DAYS ABSENT:8 > > Traceback (most recent call last): > > File "/home/ankur/PycharmProjects/STUDENTS ATTENDANCE.PY", line 17, in > > <module> > > std[i] = STUDENT(roll,name,present,absent) > > NameError: name 'std' is not defined > > > > > > THANKS IN ADVANCE > > ANKUR GUPTA > > _______________________________________________ > > BangPypers mailing list > > BangPypers@python.org > > https://mail.python.org/mailman/listinfo/bangpypers > > > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > https://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers