DoAssignment study guide
B3.2 · Document a program for later readers
Learn to document a program for later readers through clear examples and targeted practice.
Ontario Grade 10 Computer Science
Introduction to Programming
ICS2O study topic B3.2: make a program understandable to someone who reads it later
What you will learn
- Explain why a program should include documentation for later readers.
- Use clear names and brief comments to explain a program's purpose and less-obvious steps.
- Check that documentation matches what the code actually does.
1. What documentation is for
- Input is information the program receives.
- Process is the work the program does with its input.
- Output is information the program presents.
- Documentation helps a person understand the program; it does not make the program correct by itself.
2. Write documentation that helps
- Use a brief purpose comment when it helps explain the program's overall task.
- Choose names that communicate what a value means.
- Write comments for the reader, not to narrate every obvious instruction.
- Update documentation when the program changes.
3. Read and review documented code
- Follow the program from input, through process, to output.
- Compare comments with the code instead of assuming comments are correct.
- Prefer a small number of useful details over many repeated comments.
4. Practise documenting a small program
- Document the program that exists, not the program you intended to write.
- Clear names and accurate, purposeful comments work together.
- Before sharing a program, read its documentation for clarity and accuracy.
Worked example
Example 1: Make a program's purpose clear
Python 3
# Ask for the number of reusable cups needed at an event.
cup_count = input("How many cups are needed? ")
print("Cups needed:", cup_count)- Describe the taskA short purpose comment tells the reader what the program is for. The name cup_count then makes the input's meaning visible in the code.
- Trace the example inputFor the example input 24, the program stores 24 as the cup count and displays a sentence containing 24. The input is the count typed by the user; displaying the sentence is the output.
Worked example
Example 2: Explain an important value
Python 3
# Find the ticket revenue before any other costs.
ticket_count = int(input("Tickets sold: "))
# This is the price for one ticket.
price_per_ticket = float(input("Price per ticket: "))
total = ticket_count * price_per_ticket
print("Total ticket revenue:", total)- Name the valuesticket_count and price_per_ticket tell the reader what each value represents. The comment clarifies that the price is for one ticket, which helps explain why it is multiplied by the number sold.
- Follow input, process, and outputFor a hypothetical input of 8 tickets and a price of 3.5 per ticket, the process multiplies 8 by 3.5. The expected displayed total is 28. This example describes a trace; the code has not been run.
Worked example
Example 3: Check that a comment is still accurate
Python 3
# Estimate planned reading pages across several days.
pages_per_day = int(input("Pages planned each day: "))
number_of_days = int(input("Number of days: "))
planned_pages = pages_per_day * number_of_days
print("Planned pages:", planned_pages)- Compare comment and calculationThe comment says the program finds the planned total pages. The code multiplies pages_per_day by number_of_days, so the comment agrees with the process.
- Trace a sampleFor the hypothetical inputs 12 pages per day and 5 days, the calculation gives 60 planned pages. The output line displays that total. If the code were changed to add the values instead, the comment and variable names would need review.
Common mistakes and how to avoid them
Lesson summary
- Document a program so a later reader can understand its purpose and important details.
- Use meaningful names and brief, useful comments.
- Check that documentation matches the current code.
- Trace the program's input, process, and output to see whether its purpose is clear.
Check your understanding
Question 1
- This program estimates the chair cost; the entered cost is for one chair.
- Multiply chairs by cost.
- The next line is a line of code.
- This program calculates the cost of tables.
Show answer and explanation
Question 2
- Leave the comment because comments do not affect the program.
- Update the comment so it accurately describes the current program.
- Delete the variable names so the comment stands out.
- Change the output to match the outdated comment without checking the task.
Show answer and explanation
Key terms
- Documentation
- Information written with or alongside a program to help people understand it.
- Comment
- A note in source code for a reader; in Python, a comment begins with #.
- Input
- Information a program receives.
- Process
- Work a program performs on its input.
- Output
- Information a program presents.
Continue through ICS2O
View the complete ICS2O Ontario Grade 10 Computer Science curriculum and lessons
Tutor support for B3.2 · Document a program for later readers
Working on B3.2 · Document a program for later readers in ICS2O? Bring the question and your own attempt. In a live session, you can trace a small input step by step, compare expected and actual output, and test an edge case. Ask about the first step that does not make sense, then try a similar question yourself.
Explore coding tutoring · Request an eligible free 30-minute introduction. Your request is matched by subject and language; a tutor must accept before a time is confirmed.
برای مبحث B3.2 · مستندسازی برنامه برای خوانندگان بعدی در درس ICS2O، سؤال و تلاش خود را همراه بیاورید. در جلسه میتوانید یک ورودی کوچک را گامبهگام دنبال کنید، خروجی مورد انتظار و واقعی را مقایسه کنید و یک حالت مرزی را بیازمایید. راهنمای معلم برنامهنویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقهای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی میشود.
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 10 Computer Science (ICS2O), expectation B3.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.