Writing one per line and closing the file

Fill in the blanks · Basic · §9.2 Writing to a file

The code writes the tags to tags.txt, one per line, then reads the file back and prints its content exactly as it is between two --- lines. Fill in the two blanks so that every line ends with a newline and the file is closed after writing.

Code with blanks

tags = ["cat", "dog", "art"]
f = open("tags.txt", "w")
for tag in tags:
    f.write(____)
f.____

f2 = open("tags.txt", "r")
text = f2.read()
f2.close()
print("---")
print(text, end="")
print("---")

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.