I have developed a program that puts a user's username, subject, unit, score and grade into a text file. This is the code:
tests.extend([subject, unit, str(score), grade])
print tests
with open("test.txt", "a") as testFile:
for test in tests:
userName = test[0]
subject = test[1]
unit = test[2]
score = test[3]
grade = test[4]
testFile.write(userName + ';' + subject + ';' + unit + ';' + str(score) + ';' + grade + '\n')
It prints:
['abc', 'history', 'Nazi Germany', '65', 'C']
('abc' being the username)
And the following error:
grade = test[4]
IndexError: string index out of range
I don't know why I'm getting this error? Any ideas?
*Already added in previously in quiz: *
quizzes = []
quizzes.append(userName)