A file opened with "w" and nothing written
Predict the output · Medium · §9.4 Syntax that never forgets, and the contract of modes
rank.txt already exists with the content below. This week's ranking list, weekly, is still empty. Predict the output without running the code.
Code
weekly = []
with open("rank.txt", "w") as f:
for name in weekly:
f.write(name + "\n")
for name in ["yuna", "taeo"]:
with open("rank.txt", "a") as f:
f.write(name + "\n")
with open("rank.txt") as f:
print(f.read())File rank.txt
jun
sora
damiSolve 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.