if class_number == 0: #This will create and open a new text file under the name #of the class_tag variable. file = open("Class 0" + ".txt", "a") #This will write down the user's name and their score file.write(str(name) + " scored " + str(score)) #This will create a new line for each user file.write("\n") #This will close the file. file.close() import collections def new3ElementDeque(): return collections.deque(, 3) nameTop3 = collections.defaultdict(new3ElementDeque) with open("Class 0.txt") as f: for line in f: user, score = line.split(':') nameTop3[name].append(score)
I tried to get the program to only save the last three scores of the user rather than all the scores into a text file.
It looks like this now:
student scored 3 student scored 8 student scored 0 student scored 4 student scored 10 student scored 3 student scored 0 student scored 4
I want it to be like this:
student scored 3 student scored 0 student scored 4
However, the IDLE shell states:
name, score = line.split(':') ValueError: need more than 1 value to unpack
How would I get the program to store the last three scores of the user and save it to text file?
The name input is:
name = input("What is your name? ")