Code with a leftover Colab Drive path
Code review · Basic · §9.5 Where is it, and how is it written?
You got some code that someone else used in Colab with Google Drive connected. It adds today's subscriber count to the end of a record file and counts the records. When you run it, it stops with an error.
The record file subscribers.txt is in the current folder. Fix one line.
Code to fix
path = "/content/drive/MyDrive/subscribers.txt"
today = 248
with open(path, "a", encoding="utf-8") as f:
f.write(f"{today}\n")
with open(path, encoding="utf-8") as f:
lines = f.readlines()
print("Number of records:", len(lines))File subscribers.txt
210
230Solve 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.