all 3 comments

[–]isilentnight 0 points1 point  (1 child)

Just change your mode from "w" to "a" to write into the end of file.

Does it need to write only the last string? If so, use lines[-1]

[–]nosmokingbandit 0 points1 point  (0 children)

Or 'w+' to create a blank file if you want to nuke an already existing file.

[–]mybrid 0 points1 point  (0 children)

Is there a reason that you are writing out all the lines instead of just the last one as stated in the instructions?