1. Predict which files are found
Predict the output Easy ✓ CompletedRead the code and type exactly what it prints. Names are case-sensitive here. Then press Check to compare.
import os
os.makedirs("shelf", exist_ok=True)
with open("shelf/a.txt", "w") as f:
f.write("hi")
for name in ["a.txt", "A.txt", "a.txt.txt"]:
try:
with open("shelf/" + name) as f:
f.read()
print(name, "found")
except FileNotFoundError:
print(name, "missing")a.txt was created. A capital letter or an extra extension makes a different path.a.txt found
A.txt missing
a.txt.txt missing