DoAssignment study guide

C3.2 · Use documentation to build a working program

Learn to use documentation to build a working program through clear examples and targeted practice.

Ontario Grade 11 Computer Science

Computer Environments and Systems

ICS3U study topic C3.2: learn how to find, interpret, and apply instructions for programming tools

Documentation is information that explains how to use a programming language feature, such as a function or a method. It may describe what the feature does, what information it needs, what it returns, and how to use it. For expectation C3.2, the important task is to use that information while building a working program—not to guess what a command does. This lesson uses Python 3 examples. Your classroom may use another language, so the spelling and details of its documentation may differ.

What you will learn

  • Explain how documentation helps a programmer use a language feature correctly.
  • Find the input, behaviour, and result described by a documentation entry.
  • Use documented information to write and trace a short program.
  • Check that a program’s output matches its purpose and the documentation.

Read documentation before writing the call

Imagine you need a program to clean up a name typed by a user. Before choosing a command, identify the task in ordinary language: remove extra spaces at the beginning and end. Then look for documentation about a string operation that does that. Reading the entry first helps avoid a plausible-looking call that has the wrong purpose or is used in the wrong way.
When you read an entry, look for four things. First, identify the feature’s name. Second, find what information it expects, such as a string or a list. Third, read what it does to that information. Finally, check what result it provides and whether the documentation shows a useful example. These details help you decide how the feature fits into your program.
Documentation can be presented in different ways: a language reference, a help page, a built-in help system, or examples supplied with a lesson. Use information that is clearly about the language and feature you are using. If two descriptions seem to disagree, check that they refer to the same language version and feature before relying on either one.
  • Start with the task you want the program to perform.
  • Look for the expected input, the described behaviour, and the result.
  • Do not treat a command name as proof of what it does.

Connect the documentation to input, process, and output

A useful planning model is input, process, output. Input is the information the program receives. Process is the operation applied to that information. Output is the information the program displays or otherwise provides. Documentation mainly helps you understand the process and the result of a language feature; your program still needs to connect those details to its own input and output.
For example, if a person types a place name with accidental spaces, the input is the typed text. A documented string method can remove spaces at the ends. The program can then display the cleaned text. Keep the purpose of each step clear: the method produces a string result, and a separate display instruction shows it.
In Python 3, a method call is written after the value it works on, with a dot between them. Parentheses show the call. This is Python-specific syntax; another classroom language may express the same idea differently. As you write, compare your call with the documented form. Then trace the value through the program by hand: record what each variable contains and infer the displayed result. This is a reasoned prediction, not a claim that the code has been run.
  • Separate what the program receives, what it does, and what it displays.
  • Match the call’s form and input to the documentation.
  • Trace values to derive an expected result before checking a program.

Use documentation as a building and checking tool

Documentation is useful throughout a small programming task. Before writing, it helps you choose a suitable feature. While writing, it helps you use the feature correctly. After writing, it gives you a reference point for checking your reasoning: does the input have the expected kind of value, and does the described result support the next step in your program?
Keep the program’s purpose in view. A documented feature may be used correctly but still not solve the task you intended. For instance, changing the case of text is not the same as removing spaces. Check both the feature’s documented behaviour and the program’s requirements.
When a result is not what you expected, do not change code at random. Re-read the relevant entry, check the value being supplied, and trace the statements in order. If the entry includes an example, compare its structure with your call while remembering that your own values may differ. This steady check makes documentation practical: it connects a programming instruction to a clear, testable purpose.
  • Check that the feature’s behaviour matches the program’s purpose.
  • Use documentation to review a call, not just to find a command name.
  • Trace the program’s values in order to explain an expected result.

A repeatable approach

For a new task, write down what information is available and what the program should produce. Find a documented feature that appears to meet the task, and read its description and usage form. Write a small call that follows that information. Trace the relevant values and state the output you expect. Finally, compare the result against the task: a working program must use the feature appropriately and produce the intended result.
Practise this approach with familiar tasks such as cleaning text, changing text to lowercase, or finding the largest value in a short list. The aim is not to memorize every feature. It is to know how to use documentation to make a careful choice and explain why your program should work.
  • Describe the task before choosing a feature.
  • Read, write, trace, and check.
  • Be able to explain how the documentation supports your code.

Trace for the lowercase example

StageValue or action
Inputresponse contains GoOd MoRnInG
Method resultresponse.lower() gives good morning
Assignmentanswer contains good morning
Displayed outputgood morning

Worked example

Remove spaces at the ends of a name

Task: display a name without accidental spaces at its beginning or end. The documentation for Python 3 string method strip says that it returns a copy of the string with leading and trailing whitespace removed. The input is the string stored in name. Use that description to form a call and predict the displayed output.

Python 3

name = "  Ava "
clean = name.strip()
print(clean)
  1. Identify the documented behaviour
    The entry says strip returns a string with whitespace removed from the two ends. That matches the task; it does not say to remove spaces between words.
  2. Trace the value
    The input has two spaces before Ava and one after it. The method produces the cleaned string, which is assigned to clean. The print statement displays that value.
Answer: Expected displayed text: Ava
Check: The space between words would remain if the input were a multi-word name; strip removes whitespace at the ends.

Worked example

Change a response to lowercase

Task: store a response in lowercase so that later comparisons can use a consistent form. The Python 3 documentation for string method lower says it returns a lowercase version of the string. The input is the string response. Use the documented behaviour to predict the value stored in answer and the displayed output.

Python 3

response = "GoOd MoRnInG"
answer = response.lower()
print(answer)
  1. Match the method to the task
    The task is to change letter case, and the documentation describes lower as returning a lowercase version. The method is therefore a suitable choice for this input.
  2. Trace the assignment
    The input is GoOd MoRnInG. Applying lower gives good morning, so that value is assigned to answer and then displayed.
Answer: Expected displayed text: good morning
Check: The method changes letter case; it does not remove the space between the two words.

Worked example

Find the largest value in a list

Task: display the largest number in a short list of quiz scores. The Python 3 documentation for max says that, given an iterable such as a list of numbers, it returns the largest item. The input is the list scores. Use that description to predict the value stored in highest and the displayed output.

Python 3

scores = [68, 91, 84]
highest = max(scores)
print(highest)
  1. Check the input against the entry
    The list contains numbers, and the documentation describes max as returning the largest item from an iterable such as a list. The input fits that use.
  2. Trace the result
    Among 68, 91, and 84, the largest number is 91. Therefore highest receives 91, and the print statement displays 91.
Answer: Expected displayed value: 91
Check: The answer is an item from the list, not the sum or the number of items.

Common mistakes and how to avoid them

Choosing a method because its name sounds close enough to the task.
Correction: Read the documented behaviour and confirm it matches the required result.
Assuming a method changes the original value in place.
Correction: Check the documentation for what the method returns, then trace the assignment. In these examples, the returned result is assigned to a variable.
Treating a predicted output as proof that code was run.
Correction: Describe it as an expected result derived by tracing the shown statements and documented behaviour.
Ignoring whether the input suits the documented feature.
Correction: Compare the kind of input in your program with the input described by the documentation.

Lesson summary

  • Documentation explains how to use a programming feature and what result to expect.
  • Read the feature’s input, behaviour, and result before writing a call.
  • Connect a documented feature to the program’s input, process, and output.
  • Trace values by hand and check that the predicted result meets the task.

Check your understanding

Question 1

A task requires removing spaces from the beginning and end of a string. Documentation says a method returns a string with whitespace removed from both ends. What is the best next step?
  1. Use the method after confirming the input is a string, then trace the returned value.
  2. Use it without checking the result because its name sounds suitable.
  3. Assume it removes every space between words as well.
  4. Replace the string with a list of numbers.
Show answer and explanation
Use the method after confirming the input is a string, then trace the returned value.
The documented behaviour matches the task, and checking the input and tracing the returned value helps confirm the program’s expected result.

Question 2

A list contains 12, 19, and 15. Documentation says max returns the largest item in a list of numbers. What should a traced call to max on this list return?
  1. 12
  2. 19
  3. 15
  4. 46
Show answer and explanation
19
The largest listed number is 19. The documented behaviour is to return the largest item, not the sum.

Key terms

Documentation
Information explaining how to use a programming language feature.
Input
Information supplied to a program or to a feature used by the program.
Method
A named operation called using a particular value; for example, a Python string can use lower().
Trace
A step-by-step record of values and actions used to reason about a program’s expected result.
Expected output
The result predicted from the code and its inputs, without claiming the code was run.

Continue through ICS3U

View the complete ICS3U Ontario Grade 11 Computer Science curriculum and lessons

About this lesson and its review

Published by DoAssignment. This reviewed lesson follows Ontario Grade 11 Computer Science (ICS3U), expectation C3.2. It is a study resource, not an official curriculum publication.

Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.

Official curriculum reference

Report a correction or ask a question