Reputation: 7
I have the following code:
with open("students2.txt", mode="w", encoding="utf-8") as my_file:
for each_item in names:
student_grade=input("Enter the grade for " +str(each_item))
my_file.write(each_item+", "+student_grade)
When the data saves to the file I need it to save like this: each_item,student_grade so this might be Mike,78. Then the next one is saved on a new line
What have I missed?
Upvotes: 0
Views: 38
Reputation: 9969
my_file.write(each_item+", "+student_grade+"\n");
Just use this to put it on a new line.
Upvotes: 2