Interpreter error reporting

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

Interpreter error reporting

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. An interpreter finds an error on line 4 of a program. What does it do?
A Carries on and reports all errors at the end
B Stops at line 4 and reports that error
2. A program has errors on lines 3 and 8. The student runs it with an interpreter. What is shown?
A Only the error on line 3
B Both errors on lines 3 and 8
3. A program has an error on line 5. Lines 1 to 4 are correct and an interpreter runs it. What happens to lines 1 to 4?
A They have already run before the error is found
B They are not run at all
4. Line 2 of a program is fixed, but the interpreter then reports a new error on line 6. Why was it not reported earlier?
A The interpreter stopped at line 2 and never reached line 6
B The error on line 6 did not exist until line 2 was fixed
5. After fixing the error an interpreter reported, what should the programmer do next?
A Assume the program has no more errors
B Run the program again to find any further errors

Match the Pairs

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

Left columnRight column
1print("Start") print(Hello) print("End") ARun -> error on line 3 -> fix line 3 -> run again
2Line 2 has an error, line 5 has an error BThe interpreter reports only the line 2 error. The line 5 error stays hidden until line 2 is fixed.
3Lines before the error have already run, so their output appears before the error message CThis describes a compiler, not an interpreter. An interpreter stops at the first error and reports only that one.
4After the interpreter stops at an error, you fix it and run the program again to find the next error Dprint("A") print("B") print(C
5An interpreter lists every error in the whole program at once before running any code. EAn interpreter does not carry on after an error. It halts at line 4, so lines 5 to 10 do not run.
6The interpreter hits an error on line 4, so it skips line 4 and carries on running lines 5 to 10. FThe interpreter prints Start, then stops at line 2 with an error. The last line never runs.

Definitions

stops at first error

Fill in the Blanks

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

1.
print("Start") x = 10 _ 0 # interpreter stops here print("End") # never runs
2.
name = "Sam" _____(name) # runs before the error print(age) # error: age not defined
3.
x = 10 / 0 # error 1: shown first y = ___("abc") # hidden until error 1 fixed
4.
errors = 3 while errors _ 0: errors = errors - 1 # fix, run again
5.
for n in range(1, 6): if n == 3: # error found on line 3 _____ # stop, later lines never run

Spot the Error

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

Question 1
A name = input('Name: '
B print('Hello ' + name)
C print('Welcome')
Question 2
A num = '7'
B print(num + 1)
C print('Finished')
Question 3
A print('Start')
B score = 10
C print('Score: ' + score)
D print('End')
Question 4
A items = ['pen', 'ruler']
B print(items[0])
C print(items[2])
Question 5
A improt random
B num = random.randint(1, 6)
C print(num)

Answer Key

Interpreter error reporting
Section A: Quick Questions
Q1
B — Stops at line 4 and reports that error
Q2
A — Only the error on line 3
Q3
A — They have already run before the error is found
Q4
A — The interpreter stopped at line 2 and never reached line 6
Q5
B — Run the program again to find any further errors
Section B: Match the Pairs
Q1
print("Start") print(Hello) print("End") → The interpreter prints Start, then stops at line 2 with an error. The last line never runs.
Q2
Line 2 has an error, line 5 has an error → The interpreter reports only the line 2 error. The line 5 error stays hidden until line 2 is fixed.
Q3
Lines before the error have already run, so their output appears before the error message → print("A") print("B") print(C
Q4
After the interpreter stops at an error, you fix it and run the program again to find the next error → Run -> error on line 3 -> fix line 3 -> run again
Q5
An interpreter lists every error in the whole program at once before running any code. → This describes a compiler, not an interpreter. An interpreter stops at the first error and reports only that one.
Q6
The interpreter hits an error on line 4, so it skips line 4 and carries on running lines 5 to 10. → An interpreter does not carry on after an error. It halts at line 4, so lines 5 to 10 do not run.
Section C: Definitions
Q1
stops at first error — An interpreter runs code line by line and halts at the first error it finds, reporting only that one. Earlier lines have already run. Later errors stay hidden until you fix it and run again.
Section D: Fill in the Blanks
Q1
print("Start") x = 10 / 0 # interpreter stops here print("End") # never runs
Q2
name = "Sam" print(name) # runs before the error print(age) # error: age not defined
Q3
x = 10 / 0 # error 1: shown first y = int("abc") # hidden until error 1 fixed
Q4
errors = 3 while errors > 0: errors = errors - 1 # fix, run again
Q5
for n in range(1, 6): if n == 3: # error found on line 3 break # stop, later lines never run
Section E: Spot the Error
Q1
A — The closing bracket is missing, so the interpreter stops at line 1 and reports this error. No lines have run, and any mistakes later in the program stay hidden. The line should end with two brackets: input('Name: ').
Q2
B — num is text, so adding 1 gives a run-time error. The interpreter has already run line 1, stops at line 2 and never reaches line 3. The fix is int(num) + 1, then run again.
Q3
C — A string cannot be joined to a number, so the interpreter stops here at line 3. 'Start' and the score assignment have already run. Use str(score) to fix it, then run again.
Q4
C — The list only has positions 0 and 1, so items[2] is out of range. Lines 1 and 2 have already run, so 'pen' was printed. The interpreter stops at line 3 and shows only this error. The fix is items[1].
Q5
A — The keyword import is misspelt, so the interpreter stops at line 1 and reports one error. Nothing has run before it. Correct it to import random and run again to find any later errors.