King's College London · FACULTY OF ARTS & HUMANITIES

7AAVDH10 Chap.3 Booleans and Conditional Branches

- one subject, every graph, every model, every mark
6 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 3 of 6 · 7AAVDH10

Booleans and Conditional Branches

Turn a rule into a test

Boolean expressions translate comparisons, equality and membership into True or False. Conditional statements then use those results to select an indented action. This chapter keeps the test separate from the action, traces branch chains from top to bottom and checks values exactly on every threshold.

Order controls meaning

An if, elif and else chain stops after its first match.

Broad conditions can therefore make later categories unreachable. The examples expose that structural fault and show when truthiness is appropriate for empty sequences and when it would collapse a meaningful zero into a missing-value case.

In this chapter

What this chapter covers

  • 01

    Boolean values

  • 02

    Comparison operators

  • 03

    Membership tests

  • 04

    Conditional indentation

  • 05

    Branch order

  • 06

    Truthiness

Worked example · free

Classify a score by thresholds

Q [7 marks]. Place one score into high, middle or low categories with an ordered branch chain. The marks shown are a study allocation, not an official University marking scheme.
Branch order.Branch order. The chain checks the high threshold first, then the middle threshold; only the first matching action runs for a record.if score ≥ 80elif score ≥ 50elsehighmiddlelowtop-to-bottom: first match wins
Branch order. The chain checks the high threshold first, then the middle threshold; only the first matching action runs for a record.
  • 2State mutually exclusive categories. The marks shown are a study allocation, not an official University marking scheme.
  • 3Evaluate conditions from strictest to broadest.
  • 2Test every threshold boundary.
The strict high threshold is tested first, followed by the middle threshold and then else. A score stops at the first true condition, and boundary values verify whether inclusive operators match the stated rule. The marks shown are a study allocation, not an official University marking scheme.
Sia tip — Write True or False beside every condition before choosing the branch.
Glossary

Key terms

Boolean
A Boolean is either True or False and can control program flow.
Conditional
A conditional executes code according to a tested truth value.
Truthiness
Truthiness is Python's treatment of values such as empty sequences and zero as false-like.
FAQ

Booleans and Conditional Branches FAQ

Why does branch order matter?

Python stops at the first matching branch. A broad condition placed before a stricter one can capture values too early, so write categories in plain language and order overlapping thresholds deliberately.

When should I test a boundary value?

Test every value printed in a strict or inclusive comparison, plus its nearest neighbours. Those cases are where less than differs from less than or equal and where category gaps or overlaps appear.

What does a bare list condition test?

A bare list condition tests whether the list is non-empty. It says nothing about accuracy, relevance or the truth of items inside, so inspect those properties separately when the claim requires them.

How do I justify a classification threshold?

State the humanities distinction the threshold is meant to represent, then identify the evidence or convention behind it. Test the exact boundary and neighbouring values so the code matches the stated inclusion rule. If another defensible threshold would reclassify important cases, show that sensitivity and qualify the result.

Python can apply a boundary consistently, but it cannot decide that the boundary is historically or culturally meaningful without an argument and supporting sources.

Study strategy

Exam move

Write categories in plain language before translating them into comparisons. Check whether any category descriptions overlap or leave a gap. For every threshold, prepare the exact boundary value and its nearest neighbours, then predict each Boolean result. Record True or False beside the condition before following the branch. Build a descending threshold chain and explain why the stricter case must precede the broader one.

Then deliberately reverse the order and identify which category becomes unreachable. Compare the chained structure with independent if statements using the same tests. State when multiple actions are appropriate and when a single mutually exclusive label is required.

Separate condition debugging from action debugging: if the truth value is wrong, inspect input type, operator and threshold; if the truth value is right, inspect indentation and statements in the selected block. Include a year stored as text so the exercise exposes a type problem before a logic problem. Add an empty list, a non-empty list, zero and a missing value to study truthiness.

Explain why emptiness is sometimes the desired question and why zero may instead be a meaningful observation. Keep an error ledger under comparison, branch order, indentation and truthiness. For each repair, preserve unaffected categories and rerun previously passing cases. In closed-note practice, trace top to bottom and stop at the first match.

In project planning, connect every threshold to a research justification and identify the evidence that could support another boundary. Finish by writing the selected category as a sentence with its condition and scope. This final sentence proves that the code's control flow and the humanities classification express the same rule.

Add a weekly decision-table exercise with columns for input, first test, second test, selected branch and printed label. Populate it with every boundary and one clearly internal value per category. Then convert the table into code and compare each row with the program. Introduce one deliberate indentation error and one reversed threshold order, diagnose them from symptoms, and repair only the faulty structure.

End with a research reflection: explain who or what would be reclassified if the threshold moved, which evidence could justify that change and whether the resulting groups remain mutually exclusive. This final step makes the conditional an accountable analytical rule rather than an invisible convenience.

A+Everything unlocked
Unlocks this Bible + all 18 of your subjects at King's College London, plus 1,000+ more Bibles across the AskSia library.
Sia - your 7AAVDH10 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works