Skip to main content

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.

  1. For capacities [0, 5, 2, 8] and minimum 3, write the list you expect. Then do the same for minimum 2 and minimum 9.
  2. For [3, 3] with minimum 3, does the result keep one 3 or both?
  3. 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.

Filter trace
Passseats≥ 3?available
10no[]
25yes[5]
32no[5]
48yes[5, 8]

Result: [5, 8]

Starter

AP CSP pseudocode trace target · AP CSP pseudocode
capacities ← [0, 5, 2, 8]available ← []FOR EACH seats IN capacities{  IF (seats ≥ 3)  {    APPEND(available, seats)  }}DISPLAY(available)
Python starter (incomplete): rooms.py · Python
capacities = [0, 5, 2, 8]minimum = 3available = []# TODO: for each seats in capacities, append it to available if seats >= minimumprint(available)

Worked case

Worked trace for [0, 5, 2, 8], minimum 3
Passseatsseats ≥ 3?available after
10no[]
25yes[5]
32no[5]
48yes[5, 8]

Build

  1. Trace the pseudocode by hand and fill a table like the worked one.
  2. Complete the Python starter so it uses the minimum variable, not a fixed 3.
  3. Use the filter tool to check each of the five tests, including your own empty-list check.
  4. Change minimum and confirm your trace changes the way you expect.

Tests

Tests for this lab
InputExpectedWhy 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

  1. Submit your filtered list and trace for minimum 3.
  2. Explain, using this program, how a list manages complexity compared with four separate variables.

Reflect

  1. Which test would catch someone who wrote > instead of ≥?
  2. 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.