The right mode for three files

Fill in the blanks · Medium · §9.4 Syntax that never forgets, and the contract of modes

history.txt gets one new line with the subscriber count each day, and latest.txt keeps only the most recent value. backup.txt is made only once, the first time; if it already exists, the code must stop with an error instead of overwriting it. Fill in the three blanks with the right modes, including the quotes.

Code with blanks

today = 135

with open("history.txt", ____) as f:
    f.write(f"{today}\n")
with open("latest.txt", ____) as f:
    f.write(f"{today}\n")

with open("history.txt") as f:
    print("history:", f.readlines())
with open("latest.txt") as f:
    print("latest:", f.readlines())

with open("backup.txt", ____) as f:
    f.write(f"{today}\n")
print("Backup created.")

File history.txt

100
120

File latest.txt

120

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.