IDE function: error diagnostics

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

IDE function: error diagnostics

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does the error diagnostics tool in an IDE do?
A Automatically rewrites the whole program so that it has no errors
B Finds errors in the code and tells the programmer where they are and what kind they are
2. An IDE reports 'Error on line 12'. Which part of error diagnostics is this?
A The auto-completion of the code
B The line number of the error
3. An IDE shows the message 'Missing closing bracket'. What does this tell the programmer?
A What kind of error it is and what the problem is
B How fast the program will run
4. A line of code is underlined in red in the editor. What is the IDE doing?
A Highlighting faulty code so the programmer can see where the error is
B Showing that the line has been saved
5. Which tool lets a programmer pause a program at a chosen line so they can check what is happening?
A A breakpoint
B A prettyprint

Match the Pairs

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

Left columnRight column
1Error on line 12: missing colon AThe IDE underlines or highlights this faulty code, for example the missing closing bracket
2print("Total: " + score BBreakpoint set on line 8
3A breakpoint pauses the program at a chosen line so the programmer can check what is happening CError diagnostics only find and report errors (where and what kind); they do not fix the code or write the program for the programmer
4Stepping through runs the program one line at a time so the programmer can find where the error happens DStep through: line 5, then line 6, then line 7
5Error diagnostics automatically rewrite the code so it is correct EThis message has no line number and does not say what kind of error it is, so it does not diagnose the error well
6Error message: "Something is wrong" FThe IDE reports the line number of the error and a message explaining the problem

Definitions

error diagnostics

Fill in the Blanks

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

1.
print("Score: " score) Error on ____ 1: invalid syntax
2.
for i in range(5) ___________: expected ':'
3.
Set a __________ on line 3 to pause the run
4.
Debugger: ____ through the code line by line
5.
Faulty code is __________ in red by the IDE

Spot the Error

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

Question 1
A error_line = 12
B message = "Missing colon
C print("Line", error_line)
D print("Error:", message)
Question 2
A errors = ["line 3", "line 8"]
B for e in errors:
C print("Problem at", e)
D print("Total:", len(errors)
Question 3
A def show_error(line, text)
B print("Line", line)
C print("Message:", text)
D show_error(5, "Bad name")
Question 4
A error_count = 3
B if error_count = 0:
C print("Fix errors first")
D else:
E print("Ready to run")
Question 5
A total = 0
B for n in rnage(1, 4):
C total = total + n
D print("Total:", total)

Answer Key

IDE function: error diagnostics
Section A: Quick Questions
Q1
B — Finds errors in the code and tells the programmer where they are and what kind they are
Q2
B — The line number of the error
Q3
A — What kind of error it is and what the problem is
Q4
A — Highlighting faulty code so the programmer can see where the error is
Q5
A — A breakpoint
Section B: Match the Pairs
Q1
Error on line 12: missing colon → The IDE reports the line number of the error and a message explaining the problem
Q2
print("Total: " + score → The IDE underlines or highlights this faulty code, for example the missing closing bracket
Q3
A breakpoint pauses the program at a chosen line so the programmer can check what is happening → Breakpoint set on line 8
Q4
Stepping through runs the program one line at a time so the programmer can find where the error happens → Step through: line 5, then line 6, then line 7
Q5
Error diagnostics automatically rewrite the code so it is correct → Error diagnostics only find and report errors (where and what kind); they do not fix the code or write the program for the programmer
Q6
Error message: "Something is wrong" → This message has no line number and does not say what kind of error it is, so it does not diagnose the error well
Section C: Definitions
Q1
error diagnostics — An IDE tool that finds errors in code and tells the programmer where they are and what kind they are, using line numbers, error messages, highlighting and debugging tools.
Section D: Fill in the Blanks
Q1
print("Score: " score) Error on line 1: invalid syntax
Q2
for i in range(5) SyntaxError: expected ':'
Q3
Set a breakpoint on line 3 to pause the run
Q4
Debugger: step through the code line by line
Q5
Faulty code is underlined in red by the IDE
Section E: Spot the Error
Q1
B — The string is missing its closing quote. An IDE's error diagnostics would underline this line and report a syntax error. It should be message = "Missing colon".
Q2
D — The closing bracket of print() is missing, so the brackets do not match. The IDE would flag this line as a syntax error. It should end with two brackets: len(errors)).
Q3
A — A function definition must end with a colon. Without it the IDE reports a syntax error on this line. It should be def show_error(line, text):
Q4
B — A single = assigns a value, so it cannot be used as a condition. The IDE reports a syntax error here. The condition should be a comparison such as error_count > 0.
Q5
B — range is misspelt as rnage. The program stops with a run-time error saying the name is not defined, and the IDE reports the line number. It should be range(1, 4).