Unit 3 wrap-upPut it together

Everything in this unit builds on the three ingredients. Sequencing runs assignments and expressions in order (3.1 to 3.4). Selection uses Booleans to choose a path (3.5 to 3.7). Iteration repeats, and together they build algorithms (3.8, 3.9). Lists give many values one name, and traversals and searches work through them (3.2, 3.10, 3.11). Procedures package all of it under names, with parameters and return values, and libraries share it (3.12 to 3.14). Random values and simulations model the world (3.15, 3.16). And efficiency and decidability tell you which problems are practical, or possible (3.17, 3.18).
The Create task and Unit 3
Your Create task program must include a list that stores data and is then used to fulfill the program's purpose, and a procedure you wrote, with at least one parameter that affects what it does, containing an algorithm with sequencing, selection and iteration. Written response 2 asks about exactly these, in your own code.
| Prompt | Unit 3 idea it tests | What earns the point |
|---|---|---|
| 2(a) Algorithm development | Iteration, selection, sequencing | Exact passes, the exact condition, a precise change |
| 2(b) Errors and testing | Procedure calls, conditionals | Two calls that run different code, with exact results |
| 2(c) Data and procedural abstraction | Lists, procedures, parameters | How it manages complexity, and the code you would need without it |
?Wait, what's in the Personalized Project Reference again?
?Wait, how do I count loop passes for a written response?
I thought about it. Show me
Traps that cost points
The reference sheet, decoded
x ← expressiona MOD b=, ≠, >, <, ≥, ≤ / NOT, AND, ORIF (c) { } ELSE { }REPEAT n TIMES { }REPEAT UNTIL (c) { }FOR EACH item IN aList { }aList[i], INSERT, APPEND, REMOVE, LENGTHPROCEDURE f(p) { RETURN(x) }RANDOM(a, b)MOVE_FORWARD(), ROTATE_LEFT(), ROTATE_RIGHT(), CAN_MOVE(d)Strategy for Unit 3 questions
- Trace on paper: one column per variable, one row per line or per loop check. Never in your head.
- For lists, rewrite the whole list after every INSERT, APPEND, REMOVE or assignment.
- For loops, decide first: counted (REPEAT n TIMES, FOR EACH) or conditional (REPEAT UNTIL, check first).
- For "which code works" questions, test each choice with a boundary value and a tie; eliminate any that fail.
- For multiple-select questions (choose 2), judge each choice separately as true or false.
- For the written responses, use real names, real arguments and exact values from your own code.
1PROCEDURE countAtLeast(scores, goal)2{3 count ← 04 FOR EACH s IN scores5 {6 IF (s ≥ goal)7 {8 count ← count + 19 }10 }11 RETURN(count)12}
- (a) 85 and 90 are at least 80, so it returns 2.
- (b) FOR EACH runs once per element: 4 times.
Why?
Exact counts earn the point on written response 2(a). - (c) countAtLeast([95], 90) runs the IF block (95 ≥ 90) and returns 1. countAtLeast([50], 90) never runs it and returns 0.
Why?
Real calls, the code each runs, exact results: that's what 2(b) asks for. - (d) The list holds any number of scores under one name, so one loop handles them all; goal lets the same code count for any cutoff instead of writing a separate procedure for 70, 80 and 90.
Why?
For 2(c), say what the abstraction does and what you'd need without it.
Answer: (a) 2 (b) 4 times (c) countAtLeast([95], 90) returns 1; countAtLeast([50], 90) returns 0 (d) One list and one loop for any number of scores; one parameter for any cutoff.
Stuck? Get a hint
- Which scores are at least 80?
- FOR EACH runs once per element of the list in that call.
- Pick one score above the goal and one below it.
vals ← [4, 7, 1, 8]
total ← 0
i ← LENGTH(vals)
REPEAT UNTIL (i < 1)
{
IF (vals[i] MOD 2 = 0)
{
total ← total + vals[i]
}
i ← i - 1
}
DISPLAY(total)- A20
- B12
- C8
- D4
Show the answer
B. The loop walks backward from index 4 to index 1 and adds the even values: 8, then 4. The total is 12. 20 adds every value; the loop stops correctly once i reaches 0, so no index error occurs.
- AII and IV
- BI and II
- CI and III
- DIII and IV
Show the answer
A. II and IV are true: arguments set the parameters, and RANDOM includes both ends. I is false (binary search needs sorted data) and III is false (REPEAT UNTIL checks first and can run zero times).
