Pilot · Lab P03 · 60 minutes
Filter room capacities
Build a new list containing only the rooms with at least a minimum number of free seats. Keep the original order and keep duplicates. Then explain how the list makes this program simpler than separate variables would.
Predict first
Write your predictions before you use the tool.
- For capacities [0, 5, 2, 8] and minimum 3, write the list you expect. Then do the same for minimum 2 and minimum 9.
- For [3, 3] with minimum 3, does the result keep one 3 or both?
- What should an empty list produce?
Practice tool
The filter tool applies one fixed rule (keep values at least the minimum) to the list you type, up to 12 whole numbers. It shows each decision so you can check a trace. It does not run your code.
List filter · keep values at least the minimum
Up to 12 whole numbers, comma separated. Leave empty for [].
Whole number 0–999.
| Pass | seats | ≥ 3? | available |
|---|---|---|---|
| 1 | 0 | no | [] |
| 2 | 5 | yes | [5] |
| 3 | 2 | no | [5] |
| 4 | 8 | yes | [5, 8] |
Result: [5, 8]
Starter
capacities ← [0, 5, 2, 8]available ← []FOR EACH seats IN capacities{ IF (seats ≥ 3) { APPEND(available, seats) }}DISPLAY(available)capacities = [0, 5, 2, 8]minimum = 3available = []# TODO: for each seats in capacities, append it to available if seats >= minimumprint(available)Worked case
| Pass | seats | seats ≥ 3? | available after |
|---|---|---|---|
| 1 | 0 | no | [] |
| 2 | 5 | yes | [5] |
| 3 | 2 | no | [5] |
| 4 | 8 | yes | [5, 8] |
Build
- Trace the pseudocode by hand and fill a table like the worked one.
- Complete the Python starter so it uses the minimum variable, not a fixed 3.
- Use the filter tool to check each of the five tests, including your own empty-list check.
- Change minimum and confirm your trace changes the way you expect.
Tests
| Input | Expected | Why this test |
|---|---|---|
| [0, 5, 2, 8], minimum 3 | [5, 8] | Normal case. |
| [0, 5, 2, 8], minimum 2 | [5, 2, 8] | Boundary: 2 is kept because the test is ≥. Order is preserved. |
| [0, 5, 2, 8], minimum 9 | [] | No value qualifies. |
| [3, 3], minimum 3 | [3, 3] | Duplicates are both kept. |
| [], minimum 3 | [] | An empty list gives an empty result, not an error. |
Explain and reflect
Explain
- Submit your filtered list and trace for minimum 3.
- Explain, using this program, how a list manages complexity compared with four separate variables.
Reflect
- Which test would catch someone who wrote > instead of ≥?
- Where else in school could the same filter pattern be reused?
What this lab does not do
- The tool filters with one fixed rule; it does not run your Python.
- Lists are limited to 12 whole numbers from 0 to 999.
- Nothing you type is saved unless your teacher assigns the lab and you submit it.