Exercise 2: Adding notes.txt Into docs — Possible Solution ==================================================================== THE CHANGE ------------------------------ docs.add(File('notes.txt', 15)) Added directly into the existing docs Directory from this chapter's own worked example, alongside guide.md (45) and the nested Directory 'nested' (which itself contains deep.py, 30). HAND CALCULATION ------------------------------ docs' own total, before the change: guide.md (45) + nested/ (30) = 75 docs' own total, after adding notes.txt: 45 + 30 + 15 = 90 root's total, before the change, was 285 (src=200 + docs=75 + README.md=10). Adding 15 to docs should add exactly 15 to root's own total as well, since get_size() sums every child's size recursively: 285 + 15 = 300 VERIFYING AGAINST THE ACTUAL CODE ------------------------------ Running docs.get_size() gives 90, and running root.get_size() gives 300 - both match the hand calculation exactly. WHY THIS CONFIRMS COMPOSITE'S OWN RECURSIVE GUARANTEE ------------------------------ Nothing about src, README.md, or root.get_size()'s own code had to change to account for the new file - root.get_size() simply sums whatever its children currently report, and docs.get_size() (one of those children) automatically reflects the new file the moment it's added. A change three levels down the tree propagated correctly to the top-level total with zero changes to any of the surrounding code. WHY THIS WORKS AS AN ANSWER ------------------------------ The new file is added at the exact location specified, the hand calculation is shown both for docs' own subtotal and for root's overall total (rather than only the final number), and the result is verified against the actual running code, with the underlying reason (recursive summation requiring no code changes elsewhere) stated explicitly.