Due to my recent interest in Information Security and network programming, I've decided to learn Python through the Internet. I'm trying to write a piece of code which would allow the user to store the Biodata(name, age and job) of the desired number of people. And then the O/P would consist of the biodata of all of those people along with the people count. Being new to Python, I'm not able to identify the error. Thanks - Sid
Here's my code:
#!/usr/bin/python
class Bio:
counts = 0
myBio = []
def __init__(self, name, age, job):
Bio.myBio[Bio.counts] = name
Bio.myBio[Bio.counts+1] = age
Bio.myBio[Bio.counts+2] = job
Bio.counts + 1
def display(self):
for myBio in range(0, Bio.counts):
print myBio
while 1:
name = raw_input("Enter your name: ")
age = int(raw_input("Enter your age: "))
job = raw_input("Enter your Job: ")
details = Bio(name, age, job)
details.display()
print "Detail Count %d" % Bio.myBio
anymore = raw_input("Anymore details ?: (y/n)")
if anymore == 'n':
break
Here's the trace of my O/P:
./bio.py
Enter your name: Sid
Enter your age: 21
Enter your Job: InfoSec
Traceback (most recent call last):
File "./bio.py", line 25, in <module>
details = Bio(name, age, job)
File "./bio.py", line 9, in __init__
Bio.myBio[Bio.counts] = name
IndexError: list assignment index out of range*