DoAssignment study guide

B3.1 · Use clear names and indentation

Learn to use clear names and indentation through clear examples and targeted practice.

Ontario Grade 10 Computer Science

Introduction to Programming

Writing beginner programs that are easier to read

A program can give the right result and still be difficult to understand. Clear names tell a reader what information represents. Indentation—the spaces at the start of a line—shows how lines are grouped. In this lesson, we will use a small classroom example to practise both. The focus is on making code readable, not on learning new kinds of calculations or program structures.

What you will learn

  • Choose names that make a program’s values and actions easier to understand.
  • Use consistent indentation to show which lines belong together.
  • Read a short Python 3 example and trace its input, process, and output.

1. Names make meaning visible

Imagine a program that asks a student how many books they borrowed and displays that number. The keyboard entry is the input. The program stores the answer under a name, then displays it as the output. This simple input–process–output model helps us describe what the program does: information comes in, the program handles it, and information is shown.
A clear name gives a useful clue about the value it represents. For this example, borrowed_book_count is more informative than x or answer. If another reader sees the clear name later, they can understand the code without guessing. Names do not need to be long descriptions; they should be specific enough to distinguish one piece of information from another.
In Python, a name such as borrowed_book_count can be written with lowercase words separated by underscores. Choose a style that is easy to read and use it consistently. Avoid names that are so general that they hide the meaning, such as data, thing, or temp, when a more specific name is available. Also avoid changing the name for the same information partway through a program: consistent naming helps the reader follow it.
  • Prefer meaningful names over single letters or vague labels.
  • Use one consistent naming style.
  • A name should describe the information it represents.

2. Indentation shows grouping

Indentation means leaving spaces at the beginning of a line. In Python, indentation is part of the code’s structure: it shows that a line belongs inside a group introduced by a line ending in a colon. For example, the indented line under an if statement belongs to that if statement. The indentation is not decoration.
Use the same indentation consistently for lines at the same level. In the examples here, one level is four spaces. Do not use uneven spacing to make lines look aligned by eye; lines that belong together should begin at the same position. When a group ends, return to the previous indentation level.
Indentation makes it easier to see the shape of a program. A reader can quickly tell which instructions are grouped together and which are not. This lesson uses a simple if statement only to show how indentation marks a group; the main skills to practise are readable names and consistent spacing.
  • In Python, indent the lines that belong inside a grouped section.
  • Keep lines at the same level aligned consistently.
  • Return to the earlier indentation level when the group ends.

3. Read and check the code

Before writing or sharing a short program, read it as another person might. Ask: Do the names tell me what the information means? Can I see which lines belong together? Is the indentation consistent? These questions apply even when a program is short.
A useful check is to trace the example by hand. Write down the value provided as input, identify the name that stores it, and state what the program displays. This is a reading exercise, not a claim that the code has been run. The code is shown as text, and classroom programming languages may use different naming or indentation conventions.
For practice, take a small piece of code from class and replace any vague name with a more descriptive one. Then inspect each indented group and make sure its lines are aligned consistently. Keep the program’s intended actions the same while improving how clearly it communicates them.
  • Check names and indentation separately.
  • Trace the stated input to the expected output by reading the code.
  • Improve readability without changing what the program is meant to do.

Worked example

Naming a borrowed-book count

A student enters the number of books they borrowed. Show a readable way to store and display that entry.

Python 3

borrowed_book_count = input("How many books did you borrow? ")
print(borrowed_book_count)
  1. Choose a name
    The value represents a count of borrowed books, so borrowed_book_count tells the reader more than x.
  2. Trace the example
    For the hypothetical input 3, the program stores that entry under borrowed_book_count and displays the same value. This is a hand trace of the shown code, not a report of executed code.
Answer: The name borrowed_book_count makes the stored information clear.
Check: The input is 3, the process stores the entry under a descriptive name, and the expected displayed output is 3.

Worked example

Improving a vague name

A program asks how many minutes a student read. Replace the vague name minutes with a name that describes what the value represents.

Python 3

reading_minutes = input("How many minutes did you read? ")
print(reading_minutes)
  1. Identify the meaning
    The value is the number of minutes spent reading. A name such as reading_minutes communicates that meaning directly.
  2. Trace the input
    For the hypothetical entry 20, the program stores the entry as reading_minutes and displays it. The name helps a reader understand what the displayed value refers to.
Answer: Use reading_minutes rather than minutes, because the clearer name identifies what the minutes measure.
Check: The expected displayed output for the stated input is 20.

Worked example

Aligning an indented group

A program displays a reminder when a student’s entry matches the word yes. Identify how indentation helps show which line belongs to the if statement.

Python 3

wants_reminder = input("Would you like a reminder? ")
if wants_reminder == "yes":
    print("Reminder: return your book.")
  1. Notice the group
    The line that displays the reminder is indented under the if statement. That indentation shows it belongs to the statement above it. The name wants_reminder also describes the meaning of the input.
  2. Check the stated input
    For the hypothetical input yes, the condition matches, so the indented print line is the line associated with that case. For no, that line is not part of the matching case. This example is included to show grouping, not to extend the lesson beyond names and indentation.
Answer: Indent the reminder line consistently so it is visibly grouped beneath the if statement.
Check: The expected output for input yes is Reminder: return your book. The example’s purpose is to show the indented grouping.

Common mistakes and how to avoid them

Using x or data for a value whose meaning is known.
Correction: Choose a name that identifies the information, such as reading_minutes.
Using different names for the same information without a reason.
Correction: Keep the name consistent so readers can follow the value.
Treating indentation as decoration or aligning grouped lines unevenly.
Correction: Use consistent indentation to show which lines belong together.
Assuming a line belongs to a group just because it appears nearby.
Correction: In Python, check the indentation as well as the line’s position.

Lesson summary

  • Clear names help readers understand what information represents.
  • Consistent indentation shows which lines are grouped together.
  • A hand trace connects a stated input to the expected output without claiming the code was run.
  • When classroom languages differ, follow the naming and indentation conventions taught for that language.

Check your understanding

Question 1

Which name best explains a value that records the number of pages read?
  1. x
  2. reading_page_count
  3. stuff
  4. answer
Show answer and explanation
reading_page_count
reading_page_count describes the information more clearly than a vague name or a single letter.

Question 2

In the shown Python example, what does indenting the print line under the if statement communicate?
  1. The line belongs to the grouped section under the if statement.
  2. The line is a comment.
  3. The line changes the spelling of the variable name.
  4. The line is an input from the keyboard.
Show answer and explanation
The line belongs to the grouped section under the if statement.
Indentation shows that the print line is grouped under the if statement.

Question 3

If the first example receives the hypothetical input 3, what output is expected?
  1. borrowed_book_count
  2. How many books did you borrow?
  3. 3
  4. 20
Show answer and explanation
3
The entry is stored under borrowed_book_count and then displayed, so the expected displayed value is 3.

Key terms

Clear name
A name that gives a reader a useful clue about the information or action it represents.
Indentation
Spaces at the beginning of a line that show how the line is grouped with other code.
Input
Information provided to a program, such as an entry typed by a user.
Process
What a program does with information, such as storing an entry under a name.
Output
Information a program displays or otherwise provides.

Continue through ICS2O

View the complete ICS2O Ontario Grade 10 Computer Science curriculum and lessons

Tutor support for B3.1 · Use clear names and indentation

Working on B3.1 · Use clear names and indentation in ICS2O? Bring the question and your own attempt. In a live session, you can trace a small example and find the first step where the output differs from what you expected. 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.1 · کاربرد نام روشن و تورفتگی درست در درس ICS2O، سؤال و تلاش خود را همراه بیاورید. در جلسه می‌توانید یک مثال کوچک را دنبال کنید و نخستین گامی را که خروجی با انتظار شما فرق دارد پیدا کنید. راهنمای معلم برنامه‌نویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقه‌ای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی می‌شود.

About this lesson and its review

Published by DoAssignment. This reviewed lesson follows Ontario Grade 10 Computer Science (ICS2O), expectation B3.1. 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