I am writing a program that is supposed to take 10 test scores from students and their names and put that information into a list inside of a list. I saw a problem with the fact that I was repetitively .append -ing things to my 'info' list and was getting duplicate data. However, when I try to fix it the program keeps returning either empty lists or lists with only the second set of name and test scores. I do not know why this is happening, any help at all would be greatly appreciated.
I have tried:
- del info[:]
- info.clear()
- for i in range len(info): info.pop()
w
testinfo = []
score = 0
testnum = 0
name = ''
info = []
info2 = []
name = input('Enter a student name')
while name != '0':
info.append(name)
for i in range(0, 10):
testnum = testnum+1
print('Enter a score for test', testnum)
score = int(input())
info.append(score)
testnum = testnum-10
testinfo.append(info)
name = input('Enter a student name')
del info[:]
print(testinfo)
Expected result:[[student1name,1testscore1,1testscore2,etc.],[student2name,2testscore1,2testscore2,etc.]]
Actual result: [[], []]
or [[student2name,2testscore1,2testscore2,etc.], [student2name,2testscore1,2testscore2,etc.]]