I have to store the scores of people in a text file as an array, and I should be able to add each record on the array. This is the part of the code where the scores are being stored:
if group == "a":
with open("class scores A.csv", "a+") as f:
f.write("{}:{}".format(name,score))
elif group == "b":
with open("class scores B.csv", "a+") as f:
f.write("{}:{}".format(name,score))
elif group == "c":
with open("class scores C.csv", "a+") as f:
f.write("{}:{}".format(name,score))
else:
print("please enter a proper group")
However, when I add a new score, it gets added on the same line, and if the name is the same, a new record with the new name is created for example:
John, 5, John, 3, Sam, 2, instead of:
John, 5, 3
Sam, 2.
What can I do to fix this?