← Home · Student guide · Schedule · Weeks · Pseudocode · Glossary
Mini-Quiz (6–8 min) — Week 2: Procedures, Parameters, Boolean Logic
Based on: Week 1 self-study (AP Daily: variables, conditionals, loops, procedures, lists) and Week 1 in-class work
Instructions
- No notes. Show your reasoning. Time: 6–8 minutes.
- Define and call a procedure with a parameter (AP pseudocode) Write a procedure greet(name) that DISPLAYs “Hello, “ + name + “!” and show how to call it for the name “Ada”.
Answer
PROCEDURE greet(name)
DISPLAY("Hello, " + name + "!")
END PROCEDURE
# Call
greet("Ada")
Explanation: PROCEDURE defines a named block; parameter name receives the argument “Ada”.
- Return vs DISPLAY (what is printed?) What is displayed by the following?
PROCEDURE add(x, y)
RETURN x + y
END PROCEDURE
PROCEDURE add_and_show(x, y)
DISPLAY(x + y)
END PROCEDURE
DISPLAY( add(2, 3) )
result ← add_and_show(2, 3)
DISPLAY(result)
Answer
- add(2,3) returns 5 → DISPLAY prints 5.
- add_and_show(2,3) DISPLAYs 5 but RETURNS nothing (no value) → result gets null.
- DISPLAY(result) prints null.
Output (in order): 5, 5, null.
- Boolean logic (truth table reasoning) Evaluate each expression (true/false) given x ← 4, y ← 7.
a) (x < 5) AND (y = 7) b) (x ≥ 4) OR (y < 0) c) NOT(x = 4)
Answer
a) true AND true → true b) true OR false → true c) NOT(true) → false
- Input validation (REPEAT UNTIL) Write AP pseudocode that repeats INPUT() until the user enters a number from 1 to 5 (inclusive). When valid, DISPLAY(“OK”).
Answer
REPEAT
SET n ← INPUT()
UNTIL (n ≥ 1) AND (n ≤ 5)
DISPLAY("OK")
Notes: AP pseudocode treats INPUT() as text; range check shown conceptually.
- Parameter vs argument (short response) In 1–2 sentences, define parameter vs argument and give one example from Q1.
Answer
A parameter is the variable in a procedure definition (e.g., name in PROCEDURE greet(name)). An argument is the actual value passed at the call site (e.g., “Ada” in greet(“Ada”)).
- Lists (indexing is 1-based in AP pseudocode) Given L ← [“A”,”B”,”C”,”D”], answer: a) What does DISPLAY(L[3]) show? b) Write AP pseudocode to DISPLAY every item in L, one per line.
Answer
a) “C” — AP pseudocode is 1-based (L[1]=”A”, L[2]=”B”, L[3]=”C”). b)
FOR EACH item IN L
DISPLAY(item)
END FOR EACH
Notes: FOR EACH iterates elements directly; no index math needed.