OpenCyber Academy
Rapid course · Lesson 6 · English
Course code: OCA-015Lesson 06: OCA-015-A006

Two flags are independent tests

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Lesson map

Lesson 06. Map, example, EX052.

flowchart TD
  R["One tuple"] --> C["Country test"]
  R --> H["Hour test"]
  C --> J["Join only the true names"]
  H --> J
  J --> Q{"Does two names outrank one?"}
  Q -->|No| K["The script stores no weight"]

Both tests run. Neither test is a score.

Logical drawing

flag pairs, in test order
  new country, then night
join
  comma and one space
empty list
  the word ok, with no CHECK prefix

Learning outcomes

After this chapter, you should be able to:

  1. Name the two tests and the order of their labels.
  2. Explain that both tests run on every row.
  3. Refuse a weight that the script does not store.

6.1 The comprehension builds both pairs, then keeps the true ones.

The flag line builds a two-item sequence before it filters. The first pair is the label new country with the test country not in usual. The second pair is the label night with the test hour < 6 or hour >= 22. The filter keeps a label only when its test is true. Because the pairs are written out in full, the country test does not skip the hour test, and the hour test does not skip the country test.

', '.join(flags) places a comma and one space between kept labels. On both Brazil rows the kept labels are new country and then night, so the suffix is CHECK: new country, night. That order is the order of the pairs, not a severity order. The word CHECK: is added only when the list is not empty. An empty list prints the literal ok, with no prefix.

This print contains no row with exactly one flag. A UK night sign-in would keep only night. A Brazil daytime sign-in would keep only new country. Neither tuple is in the list, so neither line is in the output. Section 2.2 calls two flags a stronger lead than one. That sentence is a reader's judgment. The script stores no weight, no rank, and no sum.

Lesson table; scroll horizontally to read all columns →

Piece Role in this file
Two pairs Always constructed
if bad Keeps a label, or drops it
Join Orders kept labels as written
ok Empty-list branch

6.2 Worked example

Lesson table; scroll horizontally to read all columns →

Offered reading What the file does Decision
Both Brazil lines name two flags Both tests were true Keep
The names follow test order Country pair, then hour pair Keep
"Two flags score higher than one." No weight is stored Refuse
"A one-flag line was printed." No such tuple exists Refuse

Synthetic case. The six rows are the whole experiment.

Errors and limits

Do not add a one-flag tuple in order to illustrate the missing case.

Apply

  • EX052 — Two tests. Both Brazil lines end CHECK: new country, night. Does that order mean the country flag outranks the night flag, and does this print contain a one-flag row?
    Show marking criteria
    Rubric: 3 = no; the names follow the pair order; both tests run on every row; this print has no one-flag row; the script stores no weight;; 2 = order is the pair order and no one-flag row is present;; 1 = one flag;; 0 = none.
Worked answers

EX052. No. new country then night is the order of the two tests. Both tests run on every row. This print has no one-flag row, and the script stores no weight.