Fwd: Please help with this code

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Please help with this code

ankur gupta-2
---------- Forwarded message ---------
From: ankur gupta <[hidden email]>
Date: Sun, Aug 19, 2018 at 3:07 PM
Subject: Please help with this code
To: <[hidden email]>


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
[hidden email]
https://mail.python.org/mailman/listinfo/bangpypers
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Please help with this code

sayantan bhattacharya
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 <[hidden email]>
> Date: Sun, Aug 19, 2018 at 3:07 PM
> Subject: Please help with this code
> To: <[hidden email]>
>
>
> 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
> [hidden email]
> https://mail.python.org/mailman/listinfo/bangpypers
>
_______________________________________________
BangPypers mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/bangpypers
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Please help with this code

ankur gupta-2
Dear Sayantan, Mohit
Tried executing by implementing following change

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

std= []
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


Received following error code

ankur@ankur-Lenovo-G50-80:~/PycharmProjects$ cd /home/ankur/PycharmProjects
; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1"
/home/ankur/anaconda3/bin/python
/home/ankur/.vscode/extensions/ms-python.python-2018.4.0/pythonFiles/PythonTools/visualstudio_py_launcher.py
/home/ankur/PycharmProjects 39355 34806ad9-833a-4524-8cd6-18ca4aa74f14
RedirectOutput,RedirectOutput "/home/ankur/PycharmProjects/STUDENTS
ATTENDANCE.PY"
ENTER NAME: ANKUR
ENTER ROLL NO:1ENTER NO. OF DAYS PRESENT:12ENTER NO. OF DAYS
ABSENT:8Traceback (most recent call last):
  File "/home/ankur/PycharmProjects/STUDENTS ATTENDANCE.PY", line 18, in
<module>
    std[i] = STUDENT(roll,name,present,absent)
IndexError: list assignment index out of range

Pastebin page has been removed therefor attaching file along the mail


Thanks
Ankur Gupta

On Sun, Aug 19, 2018 at 3:59 PM Sayantan <[hidden email]> 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 <[hidden email]>
> > Date: Sun, Aug 19, 2018 at 3:07 PM
> > Subject: Please help with this code
> > To: <[hidden email]>
> >
> >
> > 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
> > [hidden email]
> > https://mail.python.org/mailman/listinfo/bangpypers
> >
>
_______________________________________________
BangPypers mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/bangpypers
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Please help with this code

Prince Sharma
In reply to this post by sayantan bhattacharya
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, <[hidden email]> 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 <[hidden email]>
> > Date: Sun, Aug 19, 2018 at 3:07 PM
> > Subject: Please help with this code
> > To: <[hidden email]>
> >
> >
> > 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
> > [hidden email]
> > https://mail.python.org/mailman/listinfo/bangpypers
> >
> _______________________________________________
> BangPypers mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/bangpypers
>
_______________________________________________
BangPypers mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/bangpypers
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Please help with this code

sayantan bhattacharya
In reply to this post by ankur gupta-2
I think you should be using some function to push in the data, not
referencing it with an offset address and then trying to push in.

The Python documents should give you the required information about the
same.

--
Sayantan Bhattacharya
[Sent from pine@dev-machine]

On Sun, 19 Aug 2018, ankur gupta wrote:

> Dear Sayantan, Mohit
> Tried executing by implementing following change
>
> 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
>
> std= []
> 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
>
>
> Received following error code 
>
> ankur@ankur-Lenovo-G50-80:~/PycharmProjects$ cd /home/ankur/PycharmProjects ; env "PYTHONIOENCODING=UTF-8"
> "PYTHONUNBUFFERED=1" /home/ankur/anaconda3/bin/python
> /home/ankur/.vscode/extensions/ms-python.python-2018.4.0/pythonFiles/PythonTools/visualstudio_py_launcher.py
> /home/ankur/PycharmProjects 39355 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput
> "/home/ankur/PycharmProjects/STUDENTS ATTENDANCE.PY"
> ENTER NAME: ANKUR
> ENTER ROLL NO:1ENTER NO. OF DAYS PRESENT:12ENTER NO. OF DAYS ABSENT:8Traceback (most recent call last):
>   File "/home/ankur/PycharmProjects/STUDENTS ATTENDANCE.PY", line 18, in <module>
>     std[i] = STUDENT(roll,name,present,absent)
> IndexError: list assignment index out of range
>
> Pastebin page has been removed therefor attaching file along the mail
>
>
> Thanks
> Ankur Gupta
>
> On Sun, Aug 19, 2018 at 3:59 PM Sayantan <[hidden email]> 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 <[hidden email]>
>       > Date: Sun, Aug 19, 2018 at 3:07 PM
>       > Subject: Please help with this code
>       > To: <[hidden email]>
>       >
>       >
>       > 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
>       > [hidden email]
>       > https://mail.python.org/mailman/listinfo/bangpypers
>       >
>
>
>
_______________________________________________
BangPypers mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/bangpypers