Midterm week: six weeks, one toolkit
420-302-VA · WEEK 7 · FALL 2026

Stage 5 of 6 · 100 points · suggested 75 minutes, closed book

Practice exam

A full paper in the style the hubs have taught all term, with worked answers and marking notes behind every question. It is a training instrument in the midterm's spirit, not a copy of the real paper, whose exact format the teacher announces in class.

How to use this paper

  • Once, properly. Late in the runway, 75 minutes on a timer, paper and pen, every hub closed, answers hidden. A practice exam taken open-book measures your searching, not your knowledge.
  • Mark honestly. Reveal each answer only after writing yours. The marking notes say what earns full and partial credit; score yourself the way a stranger would.
  • Mine the misses. Every lost point names a review page; the table at the bottom routes each section back to its material. A 70% with a study list beats an unexamined feeling of readiness.

Section A · Tools, short answers (16 points, 2 each)

A1 · Write the command: stage every change in the current repository.
git add . (naming files individually also accepted). Marking: 2 for a correct command; commands that commit or push instead score 0, they are different moves.
A2 · Your two commits from last night are not on GitHub. One command fixes it; name it and the concept behind the situation.
git push; commits are local until pushed, because the local repository and the remote are separate areas. Marking: 1 command, 1 concept.
A3 · Give the commands, in order, that refresh the package catalogue and then install the newer versions, confirming automatically.
sudo apt update then sudo apt full-upgrade -y. Marking: 1 per command in the right order; reversed order scores 1 total with the note that upgrade would act on stale information.
A4 · In SSH key authentication, which key is installed on the Pi, and which never leaves your laptop?
The public key is installed on the Pi (via ssh-copy-id); the private key never leaves the laptop. Marking: 1 each; answers sending the private key anywhere score 0 for that half.
A5 · A teammate runs sudo ufw enable on a headless Pi before any allow rule. State the consequence and the correct order.
SSH's port is blocked by default-deny, so the next connection attempt fails and the machine is unreachable over the network; recovery needs physical access. Correct order: sudo ufw allow 22, then enable. Marking: 1 consequence, 1 order.
A6 · Write the command that opens a terminal on the Pi named lastname-pi as user username, from your laptop.
ssh username@lastname-pi. Marking: 2; user and host reversed scores 0, the form is user@host.
A7 · What is the difference between rm file on the Pi and deleting a file on your desktop OS at home?
No recycle bin: rm removes immediately and permanently; the safety net, if any, is your Git history. Marking: 2 for permanence; mentioning Git as the real undo earns the second point if permanence is vague.
A8 · You see ======= in the middle of main.py after a pull. Name the situation and the three-step exit.
A merge conflict: both histories changed these lines. Exit: edit the file to the intended version and delete all markers; git add; git commit. Marking: 1 name, 1 the steps.

Section B · Electricity and GPIO (12 points)

B1 (6) · A red LED (forward voltage 2.0 V) is wired from a 3.3 V GPIO pin through a 390 Ω resistor to ground. Compute the loop current; show formula, substitution and units.
I = (V_supply − V_LED) / R = (3.3 − 2.0) / 390 = 1.3 / 390 ≈ 0.0033 A ≈ 3.3 mA. Marking: 2 formula, 2 substitution with units, 2 result sanely rounded. Dividing 3.3 by R scores the formula 0 but can still earn the arithmetic point; this is the error the question hunts.
B2 (3) · The same LED must now draw at most 2 mA. Minimum resistance, and which way do you round to a standard value?
R ≥ 1.3 / 0.002 = 650 Ω; round up (e.g., 680 Ω), since rounding down raises the current above the cap. Marking: 2 value, 1 direction with reason.
B3 (3) · A described hookup: an LED wired pin-to-ground with no resistor, its short leg toward the pin, rewired while the script runs. Name the three violations, by rule.
Rule 2 broken: no series resistor, so nothing limits the current. Polarity reversed: anode (long leg) must face the pin, so as described it will not conduct, and if later reversed without a resistor it conducts dangerously. Rule 5 broken: rewiring live. Marking: 1 per violation named with its reason.

Section C · Reading code (12 points)

C1 (6) · A script ends with this traceback. Name the error family, the faulty line's job, and the fix.
Traceback (most recent call last):
  File "blink.py", line 7, in <module>
    led.blink(0.2 0.2)
SyntaxError: invalid syntax
Read bottom-up: a SyntaxError, so Python could not parse line 7, whose job is to start the LED blinking; the two arguments lack their separating comma: led.blink(0.2, 0.2). Marking: 2 family plus the bottom-up habit, 2 locating the fault, 2 fix.
C2 (6) · Predict the complete output, then justify the final line.
def double(n):
    print(n * 2)

result = double(4)
print(result)
Output: 8 then None. The function prints 8 but has no return, so the call evaluates to None, which the second print shows. Printing and returning are different channels. Marking: 2 the 8, 2 the None, 2 the reason.

Section D · Trace (14 points)

D1 · Trace this pseudocode to completion: columns count, total, condition, OUTPUT; one row per loop pass plus the final line. 10 points for the table, 4 for the final output being right for the right reason.
SET count TO 0
SET total TO 0
WHILE count < 4
    SET count TO count + 1
    IF count = 3 THEN
        SET total TO total + 10
    ELSE
        SET total TO total + count
    END IF
END WHILE
OUTPUT total
Passcount < 4?countbranchtotal
start–0–0
10 < 4 yes1ELSE: +11
21 < 4 yes2ELSE: +23
32 < 4 yes3IF: +1013
43 < 4 yes4ELSE: +417
exit4 < 4 no4–17

OUTPUT: 17. Marking: 2 per correct pass row, 4 for 17 with the exit condition shown. The planted traps: the increment happens before the test of count = 3, and the loop runs while count is less than 4, entering at 3 one last time.

Section E · Conversions (16 points)

E1 (8) · Convert to Python, course conventions in, correct syntax out.
FUNCTION classify(ms)
    IF ms < 250 THEN
        RETURN "fast"
    ELSE IF ms < 450 THEN
        RETURN "ok"
    ELSE
        RETURN "slow"
    END IF
END FUNCTION
def classify(ms):
    if ms < 250:
        return "fast"
    elif ms < 450:
        return "ok"
    else:
        return "slow"

Marking: 2 def line, 2 if/elif/else with colons, 2 indentation as the block structure, 2 returns. ELSE IF → elif is the conversion the question watches.

E2 (8) · A night lamp spec, to a state diagram in words: OFF and ON states; a short press in either state toggles to the other; in ON, 30 minutes with no press transitions to OFF automatically. Name states, and each transition as event [guard] / action.
States: OFF, ON. Transitions: OFF →(press)→ ON / lamp on; ON →(press)→ OFF / lamp off; ON →(timeout [30 min since last press])→ OFF / lamp off. The timeout implies the machine carries memory: the time of the last press, an attribute in the class version. Marking: 2 states, 2 per transition; the timeout's guard and its implied memory carry the last two.

Section F · Spec repair (12 points, 4 each)

F1 · Repair: "The LED should blink quickly when something goes wrong."
Faults: untestable ("quickly"), ambiguous ("something goes wrong"), weak verb. One repair: "R1: When three false starts have occurred in one game, the LED shall blink at 5 Hz until the lockout ends, verified by counting flashes in slow-motion video over 2 s." Marking: 2 for naming faults by quality, 2 for a repair with ID, shall, condition, measurable tail and a check.
F2 · Repair: "The system shall be easy to use and respond fast, storing results."
Faults: not atomic (three obligations), untestable ("easy", "fast"). Repair splits it: R2: When the button is pressed, the system shall light the LED within 100 ms, verified by slow-motion video. R3: After each valid round, the system shall record the reaction time, verified by the end-of-game summary listing every round. ("Easy to use" either becomes a testable behaviour or is cut.) Marking: 2 faults, 2 the split into atomic, testable lines.
F3 · Repair: "The program shall use monotonic() in a while loop to measure the time."
Fault: it dictates how (a specific function and loop), not what. Repair: "R4: The system shall report each reaction time with an error below ±100 ms, verified against slow-motion video on five rounds." The monotonic choice then reappears where it belongs, in the design, justified by the timing rule. Marking: 2 for the what/how diagnosis, 2 for a behavioural repair.

Section G · Classes (18 points)

G1 (8) · From spec to class, on paper. D1: A new Door shall start closed. D2: open() and close() shall set the state accordingly. D3: describe() shall return "open" or "closed" to match the state.
class Door:
    def __init__(self):
        self.is_open = False      # D1

    def open(self):
        self.is_open = True       # D2

    def close(self):
        self.is_open = False

    def describe(self):           # D3
        if self.is_open:
            return "open"
        return "closed"

Marking: 2 class and __init__ shape, 2 state created through self in __init__, 2 methods with self, 2 describe returning (not printing) per spec.

G2 (4) · In the call d.open() on the class above, what is self, and rewrite the call in the form that shows it.
self is the instance d; the call is equivalent to Door.open(d). Marking: 2 each. This rewrite is the whole theory of self in one line.
G3 (6) · Predict the output and explain the fault:
class Log:
    items = []
    def add(self, x):
        self.items.append(x)

a = Log()
b = Log()
a.add(1)
print(len(b.items))
Output: 1. items is assigned in the class body, so it is a class attribute, one list on the blueprint shared by every instance; a's append is visible through b. Fix: create it per instance, def __init__(self): self.items = []. Marking: 2 the output, 2 the shared-attribute diagnosis, 2 the fix.

Marking and what your score means

SectionPointsWeak score sends you to
A · Tools16Toolkit review, then the Week 1 to 3 hub of the missed question
B · Electricity12The LED mathematics and Week 4's GPIO page
C · Reading code12Tracebacks and error families
D · Trace14Trace tables, then one trace daily until exam day
E · Conversions16The conventions table and Week 5's notations
F · Spec repair12The five qualities and Week 5's repair shop
G · Classes18The compressed core, then Week 6 in full

Rough reading: 85+ means polish and rest; 70 to 85 means two targeted sessions on the weakest sections; below 70 means rerun the review pages in order before any second attempt at timed questions. Whatever the number, the section profile is the real result.

Checklist for this stage

420-302-VA Internet of Things · Vanier College · Fall 2026 · Pravish SainathTechnical details checked against the official documentation of each tool; Raspberry Pi content CC BY-SA 4.0.