DoAssignment study guide
B2.6 · Distinguish syntax, logic and run-time errors
Learn to distinguish syntax, logic and run-time errors through clear examples and targeted practice.
Ontario Grade 10 Computer Science
Introduction to Programming
Ontario Grade 10 Computer Studies — study topic B2.6
What you will learn
- Distinguish syntax errors, logic errors, and run-time errors.
- Use a program’s input, process, and output to describe what it is meant to do.
- Identify what to check when a program does not work as intended.
1. Start with the program’s purpose
- Input is the information a program receives.
- Process is the work the program carries out.
- Output is the information the program presents.
- The intended result is the reference point for identifying a logic error.
2. Syntax errors: code that breaks language rules
- Syntax concerns whether the code is written in a form the language accepts.
- Check punctuation, spelling, and indentation when looking for a syntax error.
- Do not call every incorrect result a syntax error.
3. Logic errors: code that does the wrong thing
- A logic error is about the meaning or steps of a program, not its written form.
- Compare the program’s instructions with the task it is meant to complete.
- Test the stated boundary, especially when equality should count.
4. Run-time errors: a problem while the program runs
- A run-time error happens during program operation.
- The program may work for some inputs but fail for another.
- Describe the action and situation that caused it to stop.
Three kinds of programming error
| Error type | What goes wrong | Reading example |
|---|---|---|
| Syntax | Code breaks a language writing rule. | The if line is missing its colon. |
| Logic | The instructions do not match the intended task. | Exactly 20 minutes is treated as below the goal. |
| Run-time | A problem occurs while the program operates. | The word “many” cannot be converted to a whole number. |
Worked example
Example 1: A missing colon
Python 3
minutes = int(input("Minutes read: "))
if minutes >= 20
print("Goal reached")- Inspect the code formIn Python 3, an if condition needs a colon before the indented instruction that follows. The displayed line omits it, so the code breaks a Python writing rule.
- Name the errorThis is a syntax error. The issue is not whether 20 is the right goal; the program cannot correctly read the written if instruction until the punctuation is fixed.
- Make the correctionAdd the missing colon. The following indented line is the output instruction for the condition.
Worked example
Example 2: The equality boundary
Python 3
minutes = int(input("Minutes read: "))
if minutes > 20:
print("Goal reached")
else:
print("Keep reading")- State the intended ruleThe goal is reached at 20 minutes as well as at any larger amount. Therefore, exactly 20 should lead to the success message.
- Trace the given inputFor an input of 20, the condition “greater than 20” is false. The program therefore prints “Keep reading,” even though the stated goal has been reached.
- Classify the problemThe code is written in a form Python can read, but its condition does not match the goal. This is a logic error. Use a condition that includes equality.
Worked example
Example 3: A response that cannot become a number
Python 3
minutes = int(input("Minutes read: "))
print("Minutes entered:", minutes)- Follow the input and processThe input is the text the user types. The process tries to convert that text into a whole number so it can compare the minutes with the goal.
- Check the specific responseThe word “many” is not a whole-number entry. The conversion cannot be completed, so Python may stop with an error while the program is running.
- Distinguish the categoryThis is a run-time error, not a syntax error: the code’s form is readable. It is not the logic error shown in Example 2: the immediate problem is that this input cannot be converted as requested.
Common mistakes and how to avoid them
Lesson summary
- Syntax errors break the writing rules of a programming language.
- Logic errors occur when acceptable code does not do what the task requires.
- Run-time errors occur while a program is operating, often when a particular input or situation cannot be handled.
- Use the program’s input, process, and output, together with its intended purpose, to help tell the three categories apart.
Check your understanding
Question 1
- Syntax error
- Logic error
- Run-time error
- correctIndex": 0,
"explanation": "The line breaks a Python writing rule, so this is a syntax error."
},
{
"question": "A program runs, but it says the 20-minute goal was not reached when the goal is 20 minutes. Which error best describes this?",
"options": [
"Syntax error",
"Logic error",
"Run-time error"
],
"correctIndex": 1,
"explanation": "The program can run, but its result does not match the intended rule."
},
{
"question": "A program stops when it tries to convert the typed word “many” into a whole number. Which error best describes this?",
"options": [
"Syntax error",
"Logic error",
"Run-time error"
],
"correctIndex": 2,
"explanation": "The failure occurs during operation when the input cannot be converted as requested."
}
],
"glossary": [
{
"term": "Input",
"definition": "Information provided to a program."
},
{
Show answer and explanation
Question 2
- Syntax error
- Logic error
- Run-time error
- correctIndex": 1,
"explanation": "The program can run, but its result does not match the intended rule."
},
{
"question": "A program stops when it tries to convert the typed word “many” into a whole number. Which error best describes this?",
"options": [
"Syntax error",
"Logic error",
"Run-time error"
],
"correctIndex": 2,
"explanation": "The failure occurs during operation when the input cannot be converted as requested."
}
],
"glossary": [
{
"term": "Input",
"definition": "Information provided to a program."
},
{
"term": "Process",
"definition": "The work a program does with its input."
},
{
"term": "Output",
"definition": "Information a program presents as a result."
},
{
"term": "Syntax error",
"definition": "An error caused by code that does not follow the writing rules of its programming language."
},
{
"term":
Show answer and explanation
Question 3
- Syntax error
- Logic error
- Run-time error
- correctIndex": 2,
"explanation": "The failure occurs during operation when the input cannot be converted as requested."
}
],
"glossary": [
{
"term": "Input",
"definition": "Information provided to a program."
},
{
"term": "Process",
"definition": "The work a program does with its input."
},
{
"term": "Output",
"definition": "Information a program presents as a result."
},
{
"term": "Syntax error",
"definition": "An error caused by code that does not follow the writing rules of its programming language."
},
{
"term": "Logic error",
"definition": "An error in the program’s instructions that causes it to do something other than the intended task."
},
{
"term": "Run-time error",
"definition": "An error that happens while a program is operating."
}
]
}
Show answer and explanation
Key terms
- Input
- Information provided to a program.
- Process
- The work a program does with its input.
- Output
- Information a program presents as a result.
- Syntax error
- An error caused by code that does not follow the writing rules of its programming language.
- Logic error
- An error in the program’s instructions that causes it to do something other than the intended task.
- Run-time error
- An error that happens while a program is operating.
Continue through ICS2O
View the complete ICS2O Ontario Grade 10 Computer Science curriculum and lessons
Tutor support for B2.6 · Distinguish syntax, logic and run-time errors
Working on B2.6 · Distinguish syntax, logic and run-time errors 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.
برای مبحث B2.6 · تمایز خطای نوشتاری، منطقی و زمان اجرا در درس ICS2O، سؤال و تلاش خود را همراه بیاورید. در جلسه میتوانید یک مثال کوچک را دنبال کنید و نخستین گامی را که خروجی با انتظار شما فرق دارد پیدا کنید. راهنمای معلم برنامهنویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقهای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی میشود.
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 10 Computer Science (ICS2O), expectation B2.6. 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.