Challenge 3: pathlib File Check — Possible Solution ==================================================================== from pathlib import Path settings_dir = Path("settings") settings_dir.mkdir(exist_ok=True) # make sure the folder itself exists first config_path = settings_dir / "config.txt" if config_path.exists(): print(config_path.suffix) else: config_path.write_text("default config") print("Created config.txt with default contents") Output (first run, when config.txt doesn't exist yet): Created config.txt with default contents Output (second run, now that config.txt exists): .txt WHY THIS WORKS AS AN ANSWER ------------------------------ settings_dir / "config.txt" reuses the chapter's own Path / operator example directly — joining a folder Path with a filename string produces a new, correctly-formed Path object, without manually concatenating strings and slashes the way older code might. settings_dir.mkdir(exist_ok=True) is a necessary addition beyond what the chapter's own brief pathlib example showed: attempting to write a file into a folder that doesn't exist yet would fail, so the settings folder itself is created first. exist_ok=True prevents an error if the folder already exists from a previous run — it's a real, practical detail this challenge surfaces beyond the chapter's own minimal example. config_path.exists() reuses the chapter's own .exists() check exactly, used here in the "check-then-act" shape the challenge asks for: if the file is already there, .suffix (also reused directly from the chapter) reports its extension; if not, .write_text("default config") creates it in one call, no open()/write()/close() sequence needed, exactly the one-call convenience the chapter highlighted pathlib for.