Advantages of an interpreter

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

Advantages of an interpreter

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A student has written only the first half of a program. Which translator lets them test that half straight away?
A Compiler
B Interpreter
2. Which statement about an interpreter is correct?
A It must create a complete executable file before the program can run
B There is no wait for the whole program to be compiled before it runs
3. A program has a mistake on line 12. What does an interpreter do when it reaches that line?
A It stops at line 12, so the faulty line is easy to find
B It skips line 12 and reports every error at the very end
4. Why is an interpreter useful when a programmer is still writing a program?
A They can run and test unfinished code immediately
B They must finish the whole program before testing anything
5. Ali writes his source code on a Windows laptop. Zara has a Mac with the same interpreter installed. What is true?
A The same source code can run on Zara's Mac
B Zara must wait for a new executable file made for her Mac

Match the Pairs

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

Left columnRight column
1Interpreter: run line 1, run line 2, run line 3 AAn interpreter does not compile the whole program first. It runs the code line by line, so there is no wait before testing.
2Line 4 error -> interpreter stops at line 4 Bprint("Hello") # lines 1-2 only, rest not written yet
3An interpreter lets you test part of a program before it is finished CAn interpreter can run an unfinished program, so part of it can be tested before the rest is written.
4The same source code can run on any machine that has an interpreter DExecution halts at the faulty line, so the programmer can see exactly where the error is
5Interpreter: the whole program must be compiled first, so wait before testing EWindows + interpreter, Mac + interpreter, Linux + interpreter -> same source code
6Interpreter: the program cannot be tested until every line has been written FRuns the program straight away with no wait for compilation, so a programmer can test changes at once

Definitions

interpreter

Fill in the Blanks

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

1.
# Test this part now, the rest is unfinished ___ add(a, b): return a + b
2.
print("Line 1 runs") print(10 _ 0) print("Never reached")
3.
# No compile step: run it straight away ______ game.py
4.
total = 5 + 3 print(_____) # TODO: add the tax calculation later
5.
# Run now: it stops at any faulty line age = int(_____("Age: ")) print(age)

Spot the Error

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

Question 1
A name = input('Name? ')
B print('Hi ' + name
C print('Ready')
Question 2
A total = 0
B for n in range(3):
C total = totl + n
D print(total)
E # TODO: average
Question 3
A x = 4
B y = 6
C prnt(x * y)
Question 4
A def area(w, h)
B return w * h
C print(area(3, 4))
Question 5
A age = 15
B if age < 13:
C print('Child')
D else
E print('Teen')

Answer Key

Advantages of an interpreter
Section A: Quick Questions
Q1
B — Interpreter
Q2
B — There is no wait for the whole program to be compiled before it runs
Q3
A — It stops at line 12, so the faulty line is easy to find
Q4
A — They can run and test unfinished code immediately
Q5
A — The same source code can run on Zara's Mac
Section B: Match the Pairs
Q1
Interpreter: run line 1, run line 2, run line 3 → Runs the program straight away with no wait for compilation, so a programmer can test changes at once
Q2
Line 4 error -> interpreter stops at line 4 → Execution halts at the faulty line, so the programmer can see exactly where the error is
Q3
An interpreter lets you test part of a program before it is finished → print("Hello") # lines 1-2 only, rest not written yet
Q4
The same source code can run on any machine that has an interpreter → Windows + interpreter, Mac + interpreter, Linux + interpreter -> same source code
Q5
Interpreter: the whole program must be compiled first, so wait before testing → An interpreter does not compile the whole program first. It runs the code line by line, so there is no wait before testing.
Q6
Interpreter: the program cannot be tested until every line has been written → An interpreter can run an unfinished program, so part of it can be tested before the rest is written.
Section C: Definitions
Q1
interpreter — Runs code line by line with no wait to compile, so unfinished programs can be tested at once. It stops at the faulty line, making errors easy to find. Source code runs on any machine with one.
Section D: Fill in the Blanks
Q1
# Test this part now, the rest is unfinished def add(a, b): return a + b
Q2
print("Line 1 runs") print(10 / 0) print("Never reached")
Q3
# No compile step: run it straight away python game.py
Q4
total = 5 + 3 print(total) # TODO: add the tax calculation later
Q5
# Run now: it stops at any faulty line age = int(input("Age: ")) print(age)
Section E: Spot the Error
Q1
B — The closing bracket is missing. An interpreter runs line 1 at once, then stops at line 2 and reports the error, so the faulty line is clear. It should be print('Hi ' + name).
Q2
C — totl is a misspelt variable name. An interpreter lets you test the unfinished program straight away, and it stops at line 3 with a name error. It should be total = total + n.
Q3
C — prnt is not a real function. The interpreter runs lines 1 and 2, then stops at line 3 and points to the mistake. It should be print(x * y).
Q4
A — A function header needs a colon at the end. The interpreter stops at line 1 and reports it, so you can fix it and test again with no compile wait. It should be def area(w, h):
Q5
D — else must be followed by a colon. The interpreter stops at this line, which makes the error easy to locate. It should be else: