GRADE 7 · COMPUTING · UNIT 6 · LESSON 6.4

Sequencing and pattern recognition: Getting the message across

Boolean selection and sub-routines

Read a little. Try the workbook. Check your answers. Choose one section below to get started.

9 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Boolean selection and sub-routines

Boolean selection chooses actions from true or false conditions. A subroutine groups named steps; after a call finishes, control returns to the following step. A loop is needed to repeat input monitoring.

Today’s two goals
  • Predict outcomes for AND, inclusive OR and NOT conditions in flowcharts and MicroPython.
  • Construct or correct a selection flowchart using explicit true and false branches.
Original PaxaKids illustration for Boolean selection and sub-routines. Precise program text and data are supplied in the workbook models.
An original PaxaKids workbook scene. Use the supplied programs and data for precise workbook facts.

Explore the clues

Tap one card to find out more.

Understand the idea

Boolean selection chooses actions from true or false conditions. A subroutine groups named steps; after a call finishes, control returns to the following step. A loop is needed to repeat input monitoring.

Concept to practise: Boolean selection and sub-routines.

Work through an example

A main loop can call countdown when A OR B is true and show a sad image otherwise. The subroutine name must match its call, and its sequence must match the plan. A blocking output can delay the next input check.

Try before your workbook

With A = False and B = True, does inclusive OR call the routine? What happens when the routine reaches its final output?

Check my readiness thinking

The condition is true, so the routine is called. After its last specified action it returns to the main algorithm. Do not invent an extra delay after the final output; trace only the waits stated in the routine.

Your original programs and learning models

These original PaxaKids program and data models support your workbook. Some examples deliberately contain faults to investigate. Follow their headings and preserve exact code case, punctuation and order. Traces and supplied records are not claims of physical testing.

Combine conditions and reuse a sequence

A Boolean condition is True or False. AND requires both conditions to be True. Inclusive OR requires at least one, including both. NOT reverses one condition’s truth value.

A named subroutine groups steps that can be called from the main algorithm. After it finishes, control returns to the point after the call.

Predict every Boolean case

Predict every Boolean case — original model
ABA AND BA OR BNOT B
FalseFalseFalseFalseTrue
FalseTrueFalseTrueFalse
TrueFalseFalseTrueTrue
TrueTrueTrueTrueFalse

Read a complete AND monitoring program

This original program scrolls Boolean when both sampled button states are True. Otherwise it clears the display. It reads both states again each loop cycle. The scroll call takes time, so sampling is not continuous during that call.
Original program model
from microbit import *

while True:
    a = button_a.is_pressed()
    b = button_b.is_pressed()
    if a and b:
        display.scroll("Boolean")
    else:
        display.clear()
    sleep(30)

Compare the complete OR and NOT programs

Each program is supplied separately. Their imports, loop and output pattern are alike; the condition changes. In the NOT program, the sampled A value is unused by the condition.
INCLUSIVE OR
from microbit import *

while True:
    a = button_a.is_pressed()
    b = button_b.is_pressed()
    if a or b:
        display.scroll("Boolean")
    else:
        display.clear()
    sleep(30)
NOT B
from microbit import *

while True:
    a = button_a.is_pressed()
    b = button_b.is_pressed()
    if not b:
        display.scroll("Boolean")
    else:
        display.clear()
    sleep(30)

Trace the countdown subroutine

The main plan repeatedly checks A OR B. True calls countdown; False displays SAD. This original routine shows the countdown below, then returns. Displaying 0 is the final output; no extra one-second wait follows it here.
  1. countdown
  2. Display 3
  3. Wait 1 second
  4. Display 2
  5. Wait 1 second
  6. Display 1
  7. Wait 1 second
  8. Display 0
  9. Return

See the main monitoring structure

This diagram shows the main algorithm for the countdown program. The call uses the same name as the separate routine. Return from that routine resumes this chart after the call.

    Decision: A or B pressed?

    True branch
    1. countdown
    False branch
    1. Show SAD

    Inspect the original editable repair task

    Open https://app.diagrams.net in a browser. Use File > Open From and choose the saved Paxa .drawio file from your device. It is an original equivalent of the unavailable publisher activity.
    Inspect the original editable repair task — original model
    PartCurrent plan in the Paxa file
    Main conditionA AND B pressed?
    True branch callpulse_hearts
    False branchClear the display
    Separate routine nameheart_pulse
    Routine stepsLarge heart; wait600ms; small heart; wait600ms; Return.

    Practice files for this lesson

    Save a copy of these original PaxaKids learner files before editing in suitable software. Some code and datasets deliberately need completion or repair. Downloading a file does not run it. Use invented data; record actual tests separately from predictions. Native software practice files are not print-optimised; use the student PDF for printing.

    Paxa the Fox

    Try one step with Paxa!

    Use supplied fictional records. Do not disclose personal details, upload private photos or bypass browser warnings to complete an activity. Save personal responses before leaving.

    Our Unit 6 learning path
    1. Lesson 6.1: Prototyping
    2. Lesson 6.2: Pattern recognition
    3. Lesson 6.3: Patterns between text-based programming languages
    4. Lesson 6.4: Boolean selection and sub-routines
    5. Lesson 6.5: Project plans and test plans
    6. Lesson 6.6: Identifying errors and debugging
    7. Lesson 6.7: Sequences and lights
    8. Lesson 6.8: Creating a moving sequence of lights
    9. Lesson 6.9: Extending a light sequence
    10. Lesson 6.10: Light brightness
    11. Lesson 6.11: Loading-screen and name-sequence extensions
    12. Lesson 6.12: Final project: Sound-triggered visual alarm
    13. Lesson 6.13: Evaluation
    14. Lesson 6.14: What can you do?
    For grown-ups: using this lesson

    Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

    Read one explanation, discuss the model and try the readiness check before the workbook. Choose “Mark lesson finished” when ready. Optional account progress saves lesson position and completion across devices; save personal responses before leaving.

    2. Fill in your workbook

    Read the teaching and the complete workbook instructions. Choose, write or draw; Answer list offers larger controls. Trace code precisely and distinguish predictions from actual tests. Review designs, explanations and drawings with a grown-up.

    Boolean selection and sub-routines9 student pages · original artwork

    Opening your PDF…

    Swipe sideways across the worksheet on a small screen, or use “Answer list” for larger controls.

    TAKE YOUR PRACTICE OFFLINE

    3. Download the student worksheet

    All 9 original A4 student pages, ready for pencil-and-paper practice. Choose Review Answers to check your work on this webpage.

    Student worksheet only · PDF · 8.2 MiB · No answer key included

    Download worksheet PDF ↓

    TRY FIRST, THEN CHECK TOGETHER

    Download the student worksheet →

    4. Answers & guidance

    Finished your try? Open the guide and compare one worksheet at a time. Your own words may be different and still explain the right idea.

    Shown on this webpage only. There is no answer-key download, and this guide is left out when printing the page.

    Show answers for all 9 worksheets

    Worksheet 1

    1. Question 1: A and B are both True. What is A or B? True
    2. Question 2: What happens after a subroutine returns? the caller continues after its call

    Worksheet 2

    1. Question 3: A only is held. Which condition is True? a or b
    2. Question 4: B is held. What is not b? False
    3. Question 5: Neither button is held. What is a and b? False

    Worksheet 3

    1. Question 6: What happens for A held and B released? the display clears
    2. Question 7: What makes this repeated monitoring? the reads and selection are inside while True

    Worksheet 4

    1. Question 8: Both buttons are held. What does the OR program do? scrolls Boolean
    2. Question 9: Neither button is held. What does the NOT B program do? scrolls Boolean

    Worksheet 5

    This page introduces the activity. There are no marked responses on this sheet.

    Worksheet 6

    1. Question 10: When does the main algorithm display SAD? when neither sampled button is held

    Worksheet 7

    1. Question 11: Why is the named routine connection wrong? the call and defined routine names do not match

    Worksheet 8

    1. Question 12: In draw.io, open SubroutineActivity_Paxa.drawio. Explain what activates its main True branch and when the display clears. Repair the mismatched subroutine name so the large-heart/small-heart routine can be called; preserve its return to monitoring. On three new pages, create flowcharts for ANDprogram_Paxa.py, ORprogram_Paxa.py and NOTprogram_Paxa.py. Include every True/False path and the monitoring loop. Save and identify your edited diagram file. Original fault main call pulse_hearts versus routine heart_pulse; rename either to match consistently. Both A and B activate routine, neither or only one clears. Routine outputs HEART, waits600ms, HEART_SMALL, waits600ms, returns to caller then monitoring. Three Boolean program charts read current a/b each cycle, test a and b / a or b / not b respectively, True scroll Boolean, False clear, wait30ms, loop. AND requires both; inclusive OR includes both; NOT tests B not A. Correct decision/output/call symbols, labelled branches and unambiguous return. Actual editable file/evidence or clearly pending app steps. Do not claim a GUI test from XML validation alone. Grown-up review; personal evidence is required.

    Worksheet 9

    1. Question 13: With a partner, trace the countdown for A only, B only, both and neither; explain when the routine runs and when SAD appears. Predict each Boolean program’s outputs for all four button combinations and compare them with actual tests, or mark testing Pending. Explain how a reusable light-sequence routine could support a visual alarm, and justify an AND or OR rule using more than one relevant input. Distinguish a one-time selection from repeated monitoring and record the discussion honestly. All six source tasks retained across final work: countdown trace and triggers/inactive SAD; editable repair activation/clear/name fix; all3Boolean charts; partner reuse/multipleinput application. Countdown any heldbutton starts3,2,1,0 with3x1s waits; neitherSAD; heldbutton can retrigger after return. Boolean programs True scroll Boolean / False clear: AND FFFT, OR FTTT, NOTB TFTF in00,01,10,11 order. Actual evidence orPending, no board claim. Alarm example A enabled AND sound condition requires both; OR alternative triggers ifeither; relevant justification, routine call/return and repeated reads. V2 required if using built-in microphone, soundeventversuslevel semantics explicit if chosen. No numeric scores. Grown-up review; personal evidence is required.
    Back to my workbook ↑

    Curriculum & workbook reference

    Computing for your homeschool day

    Explore Boolean selection and sub-routines with this free Grade 7 Computing lesson. Read one idea together, try the fillable workbook and return to review at your own pace. Download the same student worksheet PDF for pencil-and-paper practice.

    Fit learning around your family’s day. There is no timer and no sign-up is needed to use the lesson. An optional account saves your lesson position and completion across devices. Workbook responses and drawings stay in this tab; save a copy of your responses before leaving.

    Understand your results

    Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

    Choose Review Answers after trying the activity. The guide stays on the webpage; the worksheet download contains only the student pages.

    For programme background, visit the Cambridge Lower Secondary Computing overview. PaxaKids provides independent original companion practice.

    The book pages identify the related teaching topic. The explanations, characters, programs and exercises here are original PaxaKids companion practice. Practical tasks require the appropriate editor and, where applicable, suitable equipment. A design or paper trace is not a verified hardware result. Only completed, reviewed lessons are listed.

    Explore the Cambridge Lower Secondary Computing curriculum for programme background. PaxaKids is an independent learning resource.