Here is my code:
import csv
with open("Grades.txt", "r") as file:
reader = csv.reader(file)
for row in reader:
if name == row[0]:
with open("Grades.txt", "a") as file:
writer = csv.writer(file)
writer.writerow(grade)
The variable name and grade have already been defined in an earlier function. I have a text file with a list of names so the code checks if the name(John) is in the text file and then is supposed to write the grade(A) next the name with a comma separating it. The problem is that my code will write the grade a space or 2 spaces below the entire list of names. If I can get it to write to the end of the name it would just be shown like (JohnA) with no separation. Im clueless about how to go about fixing this. I would appreciate if you could correct my code to do what I need it to. The variable name
is an input from a login in a different function so the input is different every time. Also new names may be added through my sign up function so the similar question doesn't help.
for example say my text file looked like this:
John
Sam
Bob
And the grade Sam got was an A. How would I append the A grade to the end of Bobs name with a comma separating the name and the grade?