Reputation:
def individualstudent():
count=1
for i in range (1,3):
sname=input('Enter name for student '+str(count) +' : ')
sID=int(input('Enter ID for student '+str(count)+' : '))
smark=int(input('Enter mark for student '+str(count)+' : '))
studno=('student'+str(count))
studno={'name':sname,'ID':sID,'mark':smark}
totaldict[count]=studno
count+=1
print(totaldict)
individualstudent()
I'm trying to create a dictionary containing 200 dictionaries. However, when I try to print the momma dictionary only the most recent one will print.
Upvotes: 1
Views: 1167
Reputation: 48417
You have to use bracket
notation in order to add elements to dictionary.
totaldict = {}
for i in range (1,201):
........................
totaldict[count] = studno
Upvotes: 1