Lesson 9.1
Writing opens the file with a mode: "w" — overwrite, "a" — append to the end.
f = open("notes.txt", "w")
f.write("First line\n")
f.close()
f = open("notes.txt", "a")
f.write("An added line\n")
f.close()
w wipes everything that was in the file. a adds after the last line. write expects
a string and does not add a line break itself: write \n by hand, otherwise the lines
run together.
The check sets the lines first and second and the file name filename. Write first
to the file in mode w, then append second in mode a — one line with \n at the end
each. Then read the file and print all its lines one by one.
First mode "w", then "a", then reading.
write expects a string and adds no line break: you have to add \n yourself.
After writing, close the file — otherwise the next open may not see it.
When reading, trim the line break with strip().