I have created an arithmetic quiz which lets the user input their name, and then 10 questions are generated. Their score is saved in a text file. I now have to save only the last three scores that they have achieved.
This is coursework so please don't give me full answers, just possibly some guidance and explanation.
I'm trying to get the names of the users into a list without the scores, so that I will be able to process them in some way. I'm using this code to create a list:
class1_list=[]
file=open("Class1.txt")
for line in file:
line.replace("\n", "")
line.split("scored")
file.close()
print(class1_list)
But I keep getting an error and I'm unsure why:
Traceback (most recent call last):
File "D:\Python\Task 3.py", line 56, in <module>
for line in file:
ValueError: I/O operation on closed file.
The layout of the scores in my text file looks like this:
John scored 7
Hannah scored 5
Tom scored 10
Jim scored 3
etc.
I'm a complete beginner with coding so would you please be able to explain in idiot terms what this error means?
Thanks for any replies.