Documentation Examples: 43 Problems with Answers
Worked examples of Documentation to try before you open each solution, then practice problems with answers.
Worked Examples
Example 1
easyShow solution
Answer
First step
Full solution
- 2. Step 2: // Calculate the sum of numbers 1 to 10. SET total = 0 // Initialise accumulator. FOR i = 1 TO 10: total = total + i // Add each number to running total. OUTPUT total // Display the result (should be 55).
- 3. Step 3: Good comments explain WHY, not just WHAT. 'Add i to total' is a bad comment (restates the code). 'Accumulate sum for average calculation' is a good comment (explains purpose).
Example 2
mediumExample 3
mediumExample 4
mediumExample 5
mediumExample 6
hardExample 7
hardExample 8
hardExample 9
hardExample 10
challengePractice Problems
Try each one, then open the solution to compare your method.
Example 1
mediumExample 2
hardExample 3
easyExample 4
easyExample 5
easyExample 6
easyExample 7
easyExample 8
easyExample 9
easyExample 10
easyExample 11
mediumExample 12
mediumExample 13
mediumExample 14
mediumExample 15
mediumExample 16
mediumExample 17
mediumExample 18
mediumExample 19
mediumExample 20
challengeExample 21
challengeExample 22
challengeExample 23
easyExample 24
easyExample 25
easyExample 26
mediumExample 27
mediumExample 28
mediumExample 29
mediumExample 30
mediumExample 31
hardExample 32
hardExample 33
hardWhat to focus on
Core idea: Code tells the computer what to do. Documentation tells humans why the code exists and how to use it.
Common stuck point: Don't document what the code does (the code itself says that). Document why it does it — the reasoning and decisions.
Ask yourself: Is the task to explain existing code to a human reader, in a comment, README or guide, without changing what it does?
Concept recap
Software documentation is the collection of written descriptions that explain how a system works and how to use it, including inline code comments, user guides, API references, design documents, and README files. Good documentation makes software understandable, usable, and maintainable by both current and future developers.
Documentation is the label on a medicine bottle: what it is for, how much to take, what not to mix it with. The pills work without the label, but nobody can use them safely. And like a label, it is only useful while it matches what is inside; a wrong label is more dangerous than a blank one.
Read the full lesson on DocumentationRelated concepts
Background knowledge
These ideas may be useful before you work through the harder examples.