A record file that was never closed
Predict the output · Medium · §9.2, §9.7 [Pair coding with AI] Asking for file code
You asked an AI to add today's follower count to the end of a record file and to check how many records there are. This is the code it gave you. followers.txt already exists with the content below. Predict the output without running the code.
Code
today = 371
log = open("followers.txt", "a")
log.write(f"{today}\n")
reader = open("followers.txt")
lines = reader.readlines()
reader.close()
print("Number of records:", len(lines))
print("Last record:", lines[-1].strip())File followers.txt
340
352Solve 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.