Membership, nested tests, comparing sequences

is this roll in the seated list? Nested ifs are and/or when the sandbox has no and. Two lists compare in full Python by the first difference — you should still write an explicit policy for campus data.

Junction traffic light

if / elif / else choose a path.

You will be able to

  • Test membership with a nested loop and a flag (in on a laptop)
  • Write nested ifs where full Python would use and/or
  • Compare two sequences with an explicit campus policy, not a silent language rule

Is this roll in the seated list?

The invigilator’s question is membership. On a laptop you write if roll in seated. Here you loop seated, set a flag when a value matches, then branch on the flag. Nested loops are not a punishment; they are the idea with the sugar peeled off.

This sandbox has no and/or in conditions. “Seated and mark at least 40” is two ifs, one inside the other. That is the same decision tree a clerk would tick on paper. When you move to a laptop you may write and — you should still be able to expand it.

Sequence compare is a policy, not a surprise

Full Python compares two lists by the first difference, like dictionary order on the items. Campus data rarely wants that silent rule. Attendance for Gate 2 matching Gate 3 should mean: same length, then each index equal, else Differ. Write that loop. If you needed “same students, any order”, you would unique both sides first — a different policy with a different function.

Do not compare a list of rolls to a list of names. Pairing is zip’s job; equality is a named check.

Words that matter

Membership
Whether a value already appears in a collection.
Nested if
The sandbox spelling of and — both tests must pass.
Sequence policy
Your written rule for when two lists “match”.

Common mistakes

Avoid: Relying on Python’s default list comparison for hall lists that must match by roll, not by accident of order.

Do this: Name the policy: same length then each index, or unique-then-compare.

Run it step by step

Each box is a real program. Press Run, change a number, Run again — the output must follow your code.

1. Step 1 — membership by a flag

19 is not in seated. Print Missing.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

2. Step 2 — nested if instead of and

Must be seated and mark >= 40. 12 with 41 prints Pass.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Example program — Two gate lists — explicit match

Same length, each index equal. Print Match.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Your turn — Refuse an unseated roll

seated is 12 and 7. roll is 19. Print Missing (not Seated).

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Self-assessment

Check your understanding before you mark the lesson complete.

1. In this sandbox, “A and B” should be written as…
2. Two attendance lists “match” when…

Progress is stored in a browser cookie on this device.