Disadvantages of an interpreter

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

Disadvantages of an interpreter

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Why does an interpreted program usually run more slowly than a compiled one?
A It is translated once and the machine code is saved
B It is translated line by line again every time it is run
2. What must a user have to run an interpreted program?
A The interpreter and the source code
B Only an executable file
3. Which statement about giving an interpreted program to users is true?
A The source code must be supplied, so users can see and copy it
B The source code stays hidden because only machine code is shared
4. A student runs the same interpreted program 10 times. How many times is it translated?
A 10 times, once for each run
B Once, then the result is reused
5. An interpreter finds errors in a program. What does it report?
A A full list of every error at the end
B One error at a time, where it stops

Match the Pairs

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

Left columnRight column
1Run 1: translate line 1, line 2, line 3... Run 2: translate line 1, line 2, line 3... AThis is wrong because an interpreter works line by line and stops at the first error, so only one error is shown at a time.
2Give the user: game.py + Python interpreter Bfor i in range(1000): translate(line) then execute(line)
3Interpreted programs run more slowly because each line is translated while the program is running CThe source code and the interpreter must both be supplied to anyone who wants to run the program
4An interpreter stops at the first error it finds, so only one error is shown at a time DThe interpreter translates the source code again from the start every time the program is run
5Once an interpreter has run a program, the user no longer needs the source code or the interpreter to run it again. EThis is wrong because the interpreter produces no saved executable file, so both the source code and the interpreter are needed every time.
6An interpreter lists every error in the whole program after translating all of it at once. FLine 4: SyntaxError (fix it, run again, then Line 9: SyntaxError)

Definitions

line by line every run

Fill in the Blanks

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

1.
Translation happens again on _____ run
2.
Interpreted code runs ______ than compiled
3.
Users need the source code and the ___________ to run the program
4.
The user must be given the ___________
5.
Only ___ error is shown at a time

Spot the Error

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

Question 1
A for line in machine_code:
B translate(line)
C execute(line)
Question 2
A runs = 3
B for run in range(1):
C translate_all()
D execute_all()
Question 3
A compiled = 10
B interpreted = 4
C if interpreted < compiled:
D print('Faster')
Question 4
A needs_source_code = False
B needs_interpreter = True
C if needs_source_code:
D print('Share source')
Question 5
A errors = 3
B shown = errors
C print(shown, 'of', errors)

Answer Key

Disadvantages of an interpreter
Section A: Quick Questions
Q1
B — It is translated line by line again every time it is run
Q2
A — The interpreter and the source code
Q3
A — The source code must be supplied, so users can see and copy it
Q4
A — 10 times, once for each run
Q5
B — One error at a time, where it stops
Section B: Match the Pairs
Q1
Run 1: translate line 1, line 2, line 3... Run 2: translate line 1, line 2, line 3... → The interpreter translates the source code again from the start every time the program is run
Q2
Give the user: game.py + Python interpreter → The source code and the interpreter must both be supplied to anyone who wants to run the program
Q3
Interpreted programs run more slowly because each line is translated while the program is running → for i in range(1000): translate(line) then execute(line)
Q4
An interpreter stops at the first error it finds, so only one error is shown at a time → Line 4: SyntaxError (fix it, run again, then Line 9: SyntaxError)
Q5
Once an interpreter has run a program, the user no longer needs the source code or the interpreter to run it again. → This is wrong because the interpreter produces no saved executable file, so both the source code and the interpreter are needed every time.
Q6
An interpreter lists every error in the whole program after translating all of it at once. → This is wrong because an interpreter works line by line and stops at the first error, so only one error is shown at a time.
Section C: Definitions
Q1
line by line every run — An interpreter translates the source code again on every run, so programs run slower and need the interpreter and source code each time. Only one error is shown at a time.
Section D: Fill in the Blanks
Q1
Translation happens again on every run
Q2
Interpreted code runs slower than compiled
Q3
Users need the source code and the interpreter to run the program
Q4
The user must be given the source code
Q5
Only one error is shown at a time
Section E: Spot the Error
Q1
A — An interpreter translates the source code line by line. It does not loop over machine code, because it never produces a saved machine code file. The line should be: for line in source_code:
Q2
B — An interpreted program is translated again on every run. The loop must repeat once per run (range(runs)), not just once, because the translation is repeated each time.
Q3
D — The interpreted program has the lower speed value because it is translated while it runs. The message should say it is slower, not faster.
Q4
A — An interpreted program cannot run without its source code, so the source code must be supplied to users. The value should be True.
Q5
B — An interpreter stops at the first error it finds, so only one error is shown at a time. The line should be: shown = 1