Syntax Errors and Debugging

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Syntax Errors and Debugging

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does Python do when it finds a syntax error?
A Stops and shows an error message
B Skips the line and continues
2. Where does the error message appear in the editor?
A The console panel
B The code area
3. What does the error message tell you that helps you debug?
A The line number of the problem
B The fixed version of the code
4. A missing closing quote on a string causes a syntax error.
A False
B True
5. What should you do after fixing a syntax error?
A Click Reset to start over
B Click Run to test the fix

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1syntax error A# SyntaxError on line 3 # Check line 3 for a typo
2print("Hello, world!) BSyntax error — the closing quote is missing from the string
3Debugging means finding and fixing the error in your code C# Find the bug # Fix it # Click Run to test
4The error message shows the line number where Python got confused DSyntax error — string must be wrapped in quote marks
5print(Hello, world!) EWrong — Python stops immediately and shows an error message
6# Python keeps running after a syntax error FAn error caused by a typo, missing quote, or wrong bracket that stops Python running

Definitions

syntax error

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
# A ______ error means Python cannot run
2.
print("Hello, world") # no ______ error
3.
# Fix the bug then click ___ again
4.
# Read the error to find the line ______
5.
print("Hello) # missing _____

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A # Python keeps running after a syntax error
B # Syntax errors are caused by typos
C # Python shows an error message with a line number
Question 2
A # A missing quote causes a syntax error
B # Python ignores syntax errors automatically
C # Fix the bug and click Run to test the fix
Question 3
A # The error message shows the line number
B # Read the error to find where the bug is
C # Syntax errors only happen on the last line
Question 4
A # Only beginners make syntax errors
B # Debugging means finding and fixing the error
C # A wrong bracket can cause a syntax error
Question 5
A # Syntax errors are shown in the console
B # After fixing a bug click Reset to re-test
C # The error message includes a line number

Answer Key

Syntax Errors and Debugging
Section A: Quick Questions
Q1
A — Stops and shows an error message
Q2
A — The console panel
Q3
A — The line number of the problem
Q4
B — True
Q5
B — Click Run to test the fix
Section B: Match the Pairs
Q1
syntax error → An error caused by a typo, missing quote, or wrong bracket that stops Python running
Q2
print("Hello, world!) → Syntax error — the closing quote is missing from the string
Q3
Debugging means finding and fixing the error in your code → # Find the bug # Fix it # Click Run to test
Q4
The error message shows the line number where Python got confused → # SyntaxError on line 3 # Check line 3 for a typo
Q5
print(Hello, world!) → Syntax error — string must be wrapped in quote marks
Q6
# Python keeps running after a syntax error → Wrong — Python stops immediately and shows an error message
Section C: Definitions
Q1
syntax error — An error that occurs when Python cannot understand your code due to a typo, missing quote, or wrong bracket; Python stops and shows a message with the line number
Section D: Fill in the Blanks
Q1
# A syntax error means Python cannot run
Q2
print("Hello, world") # no syntax error
Q3
# Fix the bug then click Run again
Q4
# Read the error to find the line number
Q5
print("Hello) # missing quote
Section E: Spot the Error
Q1
A — Python stops immediately when it finds a syntax error — it does not keep running. Line 0 is wrong.
Q2
B — Python does not ignore syntax errors — it stops and shows an error message. Line 1 is wrong.
Q3
C — Syntax errors can happen on any line, not just the last one. Line 2 is wrong.
Q4
A — Every programmer makes syntax errors — they are a normal part of coding at any skill level. Line 0 is wrong.
Q5
B — After fixing a bug you should click Run to re-test, not Reset. Reset only restores starter code. Line 1 is wrong.