Choosing a language level for a scenario

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

Choosing a language level for a scenario

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A school builds a homework app that must run on Windows, macOS and Chromebooks. Which language level should it choose?
A Low-level language
B High-level language
2. A programmer is writing a device driver that must control a printer's hardware directly. Which language level fits best?
A Low-level language
B High-level language
3. Which justification is stronger for choosing a high-level language for a web app?
A It is machine independent, so it can run on many different devices.
B It is a good choice because high-level is newer.
4. An embedded controller in a washing machine has very little memory and needs exact control of its hardware. Which language level is more suitable?
A Low-level, for direct hardware control and efficient use of memory
B High-level, because it is machine independent
5. Which statement about a program that must run on many different machines is correct?
A Choose low-level, because machine code works on every processor.
B Choose high-level, because the same source code can be translated for each machine.

Match the Pairs

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

Left columnRight column
1Scenario: a web app for many different computers AHigh-level, because the app must be portable and run on many machines
2Scenario: a device driver that controls a printer BLow-level, because the controller needs direct access to hardware
3A justified answer links the language level to a need of the task CLow-level code is machine dependent, so it is not portable. A high-level language should be chosen.
4An embedded controller needing exact memory and hardware control suits a low-level language DChoose a high-level language, because it is machine independent and runs on many machines
5Use assembly language for a portable app that must run on many different computers EThe answer gives no justification. It must link the choice to the task's needs, such as direct hardware control.
6Use a high-level language because it is good. (no link to the task) FChoose a low-level language, because it can directly manipulate the hardware

Definitions

choose language level

Fill in the Blanks

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

1.
IF runsOnManyMachines THEN level ← "__________" ENDIF
2.
IF task = "device driver" THEN level ← "_________" ENDIF
3.
needsPortability ← TRUE IF ________________ = TRUE THEN level ← "high-level"
4.
level ← "high-level" reason ← "it runs on many machines" ______ level + " because " + reason
5.
IF device _ "embedded controller" THEN level ← "low-level" ENDIF

Spot the Error

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

Question 1
A portable = True
B hw = False
C level = "low-level"
D if portable and hw:
E level = "high-level"
Question 2
A task = "device driver"
B needs_hardware = False
C if needs_hardware:
D print("low-level")
Question 3
A task = "web app"
B machines = 500
C if machines < 1:
D print("high-level")
Question 4
A task = "washing machine chip"
B memory_tiny = True
C if not memory_tiny:
D print("low-level")
Question 5
A level = "high-level"
B why = "runs on many machines"
C print(level, "as", reason)

Answer Key

Choosing a language level for a scenario
Section A: Quick Questions
Q1
B — High-level language
Q2
A — Low-level language
Q3
A — It is machine independent, so it can run on many different devices.
Q4
A — Low-level, for direct hardware control and efficient use of memory
Q5
B — Choose high-level, because the same source code can be translated for each machine.
Section B: Match the Pairs
Q1
Scenario: a web app for many different computers → Choose a high-level language, because it is machine independent and runs on many machines
Q2
Scenario: a device driver that controls a printer → Choose a low-level language, because it can directly manipulate the hardware
Q3
A justified answer links the language level to a need of the task → High-level, because the app must be portable and run on many machines
Q4
An embedded controller needing exact memory and hardware control suits a low-level language → Low-level, because the controller needs direct access to hardware
Q5
Use assembly language for a portable app that must run on many different computers → Low-level code is machine dependent, so it is not portable. A high-level language should be chosen.
Q6
Use a high-level language because it is good. (no link to the task) → The answer gives no justification. It must link the choice to the task's needs, such as direct hardware control.
Section C: Definitions
Q1
choose language level — Pick high-level for portable programs on many machines; pick low-level for direct hardware control, like drivers. Then justify the choice by linking it to the task's needs.
Section D: Fill in the Blanks
Q1
IF runsOnManyMachines THEN level ← "high-level" ENDIF
Q2
IF task = "device driver" THEN level ← "low-level" ENDIF
Q3
needsPortability ← TRUE IF needsPortability = TRUE THEN level ← "high-level"
Q4
level ← "high-level" reason ← "it runs on many machines" OUTPUT level + " because " + reason
Q5
IF device = "embedded controller" THEN level ← "low-level" ENDIF
Section E: Spot the Error
Q1
D — High-level is chosen for a portable program that does not need direct hardware control. The condition should be 'portable and not hw'.
Q2
B — A device driver must control hardware directly, so needs_hardware should be True. Otherwise the low-level branch never runs.
Q3
C — A program that runs on many machines needs a portable high-level language. The test should be machines > 1, not < 1.
Q4
C — An embedded controller with tiny memory needs efficient low-level code. The test should be 'if memory_tiny:' so the low-level branch runs.
Q5
C — The justification variable is called why, so reason is undefined and causes an error. It should be print(level, "as", why).