GRADE 8 · COMPUTING · UNIT 1 · LESSON 1.27

Computational thinking and programming

Set and use Boolean flags

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

Topic 1.27 · Set and use Boolean flags12 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Set and use Boolean flags

A Boolean flag records a true-or-false state. Assign and update it deliberately; a comparison can produce its value. Use the flag to explain why a later conditional action runs.

Today’s two goals
  • Trace comparisons, store results in flags and combine flags in a quiz.
  • Explain my method and support it with a labelled trace, example or test record.
Original PaxaKids illustration for Set and use Boolean flags. Use the supplied program and data models for precise workbook facts.
An original PaxaKids workbook scene. Use the supplied programs and data for precise workbook facts.

Work through an example

Set packed = False, then packed = (count == required). For count 5 and required 5, packed becomes True because the equality comparison succeeds.

Try before your workbook

If count is 4 and required is 5, what value should that flag hold?

Explore the clues

Tap one card to find out more.

Understand the idea

A Boolean flag records a true-or-false state. Assign and update it deliberately; a comparison can produce its value. Use the flag to explain why a later conditional action runs.

Concept to practise: Set and use Boolean flags.

Work through an example

Set packed = False, then packed = (count == required). For count 5 and required 5, packed becomes True because the equality comparison succeeds.

Try before your workbook

If count is 4 and required is 5, what value should that flag hold?

Check my readiness thinking

False. The flag reflects the comparison result; it is not the text "False" or the count itself.

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.

Store a condition as a Boolean flag

A flag is a named variable that records a state or whether something has happened. A robot-readiness flag can record whether enough pieces are available; quiz flags can record whether answers match.

Use meaningful names and genuine True/False values. The stored flag can be tested later without rewriting the full comparison every time.

Trace a flag that begins False

This original program starts ready at False. It changes ready to True only when pieces is at least 12, then prints the stored flag. First read it exactly as shown before changing the number.
Original Paxa readiness-flag program
ready = False
pieces = 15
if pieces >= 12:
    ready = True
print(ready)

Change the number and retest the boundary

Treat each row as a fresh run of page 2 with only the pieces value changed. The initial ready = False is performed again in every run.
Change the number and retest the boundary — original model
PiecesStored ready before print
0{'clue': 'True or False', 'prompt': 'Ready for 0 pieces', 'answers': ['False']}
11{'clue': 'True or False', 'prompt': 'Ready for 11 pieces', 'answers': ['False']}
12{'clue': 'True or False', 'prompt': 'Ready for 12 pieces', 'answers': ['True']}
15{'clue': 'True or False', 'prompt': 'Ready for 15 pieces', 'answers': ['True']}

Compare an IF/ELSE with direct comparison assignment

Both original versions read valid nonnegative integer pieces and store the same Boolean result. The comparison itself produces True or False, so the direct version stores that result in ready.
A: explicit assignment blocks
pieces = int(input())
if pieces >= 12:
    ready = True
else:
    ready = False
B: store comparison result
pieces = int(input())
ready = pieces >= 12

Use a Boolean flag with valid Python syntax

For an actual Boolean ready, both forms below choose the action when ready is True. Keep the colon and indentation. Assignment with a single = is not an equality test in an if header.
A: direct Boolean test
ready = True
if ready:
    print("Ready")
B: explicit comparison
ready = True
if ready == True:
    print("Ready")

Trace two quiz flags and combine them

This original program asks two arithmetic questions and reads valid integer answers. The questions print before their inputs. Each comparison stores a Boolean flag; feedback is Both match, One matches or Neither matches. The feedback describes matches without giving a numeric grade.
Original Paxa two-question flag quiz
print("What is 3 * 4?")
first = int(input())
if first == 12:
    correct1 = True
else:
    correct1 = False
print("What is 21 / 3?")
second = int(input())
if second == 7:
    correct2 = True
else:
    correct2 = False
if correct1 and correct2:
    print("Both match")
elif correct1 or correct2:
    print("One matches")
else:
    print("Neither matches")

Complete all four two-flag combinations

Use page 6. The first expected answer is 12 and the second is 7. Fill both Boolean flags and only the final feedback message; the question prompts are not included in the feedback column.
Complete all four two-flag combinations — original model
FirstSecondFlag AFlag BFeedback
127{'clue': 'True or False', 'prompt': 'First flag for 12/7', 'answers': ['True']}{'clue': 'True or False', 'prompt': 'Second flag for 12/7', 'answers': ['True']}{'clue': 'Final message', 'prompt': 'Quiz feedback for 12/7', 'answers': ['Both match']}
117{'clue': 'True or False', 'prompt': 'First flag for 11/7', 'answers': ['False']}{'clue': 'True or False', 'prompt': 'Second flag for 11/7', 'answers': ['True']}{'clue': 'Final message', 'prompt': 'Quiz feedback for 11/7', 'answers': ['One matches']}
128{'clue': 'True or False', 'prompt': 'First flag for 12/8', 'answers': ['True']}{'clue': 'True or False', 'prompt': 'Second flag for 12/8', 'answers': ['False']}{'clue': 'Final message', 'prompt': 'Quiz feedback for 12/8', 'answers': ['One matches']}
118{'clue': 'True or False', 'prompt': 'First flag for 11/8', 'answers': ['False']}{'clue': 'True or False', 'prompt': 'Second flag for 11/8', 'answers': ['False']}{'clue': 'Final message', 'prompt': 'Quiz feedback for 11/8', 'answers': ['Neither matches']}

Identify the quiz data and stored results

The two input variables store integers. The two correctness variables store Boolean comparison results, not the original answer values. The final condition combines those flags.
Identify the quiz data and stored results — original model
VariableMeaningPython type
firstFirst numeric answer{'clue': 'int or bool', 'prompt': 'Type of first', 'answers': ['int', 'integer']}
secondSecond numeric answer{'clue': 'int or bool', 'prompt': 'Type of second', 'answers': ['int', 'integer']}
correct1Whether first equals 12{'clue': 'int or bool', 'prompt': 'Type of correct1', 'answers': ['bool', 'Boolean']}
correct2Whether second equals 7{'clue': 'int or bool', 'prompt': 'Type of correct2', 'answers': ['bool', 'Boolean']}

Plan a third question and four feedback outcomes

Extend the quiz with the original third question What is 19 - 14? Its integer answer is 5. Store its comparison result in correct3. Use the following complete feedback policy, checking all-three before pairs and pairs before any-single.
Plan a third question and four feedback outcomes — original model
Matching flagsFeedback
All three trueEvery answer matches
Exactly two trueA pair matches
Exactly one trueOne answer matches
All three falseNo answers match

Reflect with a consistent labelled scale

Choose one description based on actual work, then cite a precise example and one next step. The labels follow the source scale from strongest independence to greatest support; no numeric confidence rating is used.
Reflect with a consistent labelled scale — original model
DescriptionEvidence-based meaning
Ready independentlyI can explain and change flag programs using evidence.
Mostly readyI can do most parts with occasional prompts.
Partly readySome parts are clear; I can name what needs practice.
BeginningI understand a few parts and need guided practice.
Need supportI need help to trace or create the flags accurately.

Files for this activity

Use these original PaxaKids practice files with the matching workbook. Work on a local copy in the appropriate editor. Some examples deliberately contain faults to investigate; a downloaded file is not a completed practical test.

Paxa the Fox

Try one step with Paxa!

Trace code in the stated order and preserve exact spelling and case. Use fictional data. Label a prediction, paper trace, simulator run and physical-device test separately; an unperformed test stays Pending. Save personal responses before leaving.

Our Unit 1 learning path
  1. Lesson 1.1: Recall algorithms and representations
  2. Lesson 1.2: Purpose and conventions of pseudocode
  3. Lesson 1.3: Input, output and strings
  4. Lesson 1.4: Identifiers and assignment
  5. Lesson 1.5: Arithmetic and translation
  6. Lesson 1.6: Trace and review a sequence
  7. Lesson 1.7: Conditions and two-way flow
  8. Lesson 1.8: IF THEN and indentation
  9. Lesson 1.9: IF THEN ELSE and decision diagrams
  10. Lesson 1.10: Ordered ELSEIF and fallback ELSE
  11. Lesson 1.11: Match flowchart and pseudocode branches
  12. Lesson 1.12: AND, OR and NOT
  13. Lesson 1.13: Grouping, precedence and review
  14. Lesson 1.14: Why software searches
  15. Lesson 1.15: A successful linear search
  16. Lesson 1.16: An unsuccessful search and termination
  17. Lesson 1.17: Practise and communicate the search
  18. Lesson 1.18: Translate conditions into Python
  19. Lesson 1.19: One-branch IF programs
  20. Lesson 1.20: Two-way IF ELSE programs
  21. Lesson 1.21: Ordered ELIF choices
  22. Lesson 1.22: Ranges and independent decisions
  23. Lesson 1.23: Boolean operators in Python
  24. Lesson 1.24: Design and test recommendations
  25. Lesson 1.25: Trace, debug and reflect
  26. Lesson 1.26: Choose data types and recognise Boolean literals
  27. Lesson 1.27: Set and use Boolean flags
  28. Lesson 1.28: Explain and identify constants
  29. Lesson 1.29: Express constants in three algorithm forms
  30. Lesson 1.30: Use a fixed factor in a calculation
  31. Lesson 1.31: Cast to Boolean and validate an empty response
  32. Lesson 1.32: Recall calls and trace return values
  33. Lesson 1.33: Supply parameters and reuse library code
  34. Lesson 1.34: Choose and import libraries responsibly
  35. Lesson 1.35: Round with floor and ceiling
  36. Lesson 1.36: Use pi and investigate another mathematical feature
  37. Lesson 1.37: Generate random choices within bounds
  38. Lesson 1.38: Investigate random real values and review library use
  39. Lesson 1.39: Retrieve test tables and predict selection outcomes
  40. Lesson 1.40: Decompose everyday problems
  41. Lesson 1.41: Decompose programs and organise shared work
  42. Lesson 1.42: Develop through repeated build/test cycles
  43. Lesson 1.43: Predict and verify algorithm outcomes
  44. Lesson 1.44: Choose representative and boundary tests
  45. Lesson 1.45: Build, execute and review a test plan
  46. Lesson 1.46: Recall physical inputs and compare transmission media
  47. Lesson 1.47: Configure a radio group and agree a message scheme
  48. Lesson 1.48: Send and receive numbers and strings
  49. Lesson 1.49: Trace numeric message sequences
  50. Lesson 1.50: Transmit text and use received data in conditions
  51. Lesson 1.51: Diagnose and extend a message protocol
  52. Lesson 1.52: Review communication and evidence of testing
  53. Lesson 1.53: Project 1: Adventure story
  54. Lesson 1.54: Project 2: Fire, Water, Earth
  55. Lesson 1.55: Check your progress 1
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 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.

Set and use Boolean flags12 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 12 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.5 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 12 worksheets

Worksheet 1

  1. Question 1: Which is a meaningful name for a Boolean readiness state? ready
  2. Question 2: What type should a flag have in these examples? bool

Worksheet 2

  1. Question 3: What integer is stored in pieces as shown? 15
  2. Question 4: What value is stored in ready immediately before print? True
  3. Question 5: What does the program print? True

Worksheet 3

  1. Question 6: Ready for 0 pieces False
  2. Question 7: Ready for 11 pieces False
  3. Question 8: Ready for 12 pieces True
  4. Question 9: Ready for 15 pieces True
  5. Question 10: Which variable is Boolean in the program? ready

Worksheet 4

  1. Question 11: For input 11, do the versions store the same flag? yes, both store False
  2. Question 12: If pieces changes later, does stored ready automatically recalculate? no, the comparison must be evaluated again to update it

Worksheet 5

  1. Question 13: Which shown forms are valid for this Boolean flag? A and B
  2. Question 14: Repair the invalid header if ready = True: using either valid form. if ready: / if ready == True:
  3. Question 15: Which representation should ready store here? True without quotes

Worksheet 6

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

Worksheet 7

  1. Question 16: First flag for 12/7 True
  2. Question 17: Second flag for 12/7 True
  3. Question 18: Quiz feedback for 12/7 Both match
  4. Question 19: First flag for 11/7 False
  5. Question 20: Second flag for 11/7 True
  6. Question 21: Quiz feedback for 11/7 One matches
  7. Question 22: First flag for 12/8 True
  8. Question 23: Second flag for 12/8 False
  9. Question 24: Quiz feedback for 12/8 One matches
  10. Question 25: First flag for 11/8 False
  11. Question 26: Second flag for 11/8 False
  12. Question 27: Quiz feedback for 11/8 Neither matches

Worksheet 8

  1. Question 28: Type of first int / integer
  2. Question 29: Type of second int / integer
  3. Question 30: Type of correct1 bool / Boolean
  4. Question 31: Type of correct2 bool / Boolean
  5. Question 32: What does correct1 and correct2 require? both stored Boolean flags to be true

Worksheet 9

  1. Question 33: Why must all-three be checked before any matching pair? all-three also contains a matching pair
  2. Question 34: How many True/False combinations exist for three flags? 8

Worksheet 10

  1. Question 35: Which is useful evidence for a confidence description? a correct boundary trace and explanation of a change

Worksheet 11

  1. Question 36: Modify the readiness example to read a valid nonnegative integer pieces value. Store whether it is at least 12 in a Boolean ready flag. Then use the flag to print Ready to build for True or Collect more pieces for False. Show either explicit if/else flag assignment or direct comparison assignment, followed by a valid flag test. Test 0, 11, 12 and 15 with predictions and actual output or Pending. Explain the types of pieces and ready and why a later change to pieces would require recalculating ready. Cite full code and tests if saved. Integer input, ready bool from pieces >= 12 via complete if/else or direct assignment, if ready: or if ready == True: with colon/four spaces and defined opposite feedback. Inputs 0/11 -> Collect more pieces;12/15 -> Ready to build. Types int/bool distinct, flag stores evaluated state and is not a live formula; recompute after changing pieces if updated state needed. Full source and exact prediction/actual or Pending evidence, correction/retest if any, no real hardware or learner GUI claim and no numeric marks. Grown-up review; personal evidence is required.

Worksheet 12

  1. Question 37: Extend the complete page 6 quiz with the page 9 third question and a Boolean correct3 flag. Implement all four feedback outcomes in their stated order without numeric scores. Identify every answer variable and flag with its Python type. Test all eight planned input combinations in the supplied record, predicting flags and final feedback before actual output or Pending. Keep full source and records, explain any correction and retest, and choose a page 10 confidence description supported by evidence. Describe actual individual or partner work and one next step honestly. Three questions expected answers 12,7,5; all answer variables int, three flags bool. First test all flags with and; then any pair: (c1 and c2) or (c1 and c3) or (c2 and c3); then any single with or; else none. Feedback Every answer matches/A pair matches/One answer matches/No answers match, no numerical grade. All eight planned combinations tested, exact flags and output agree, full source/predictions/actual or Pending, correction/retest evidence. Equivalent consistent logic accepted, no arbitrary truthy strings. Confidence description in stated strongest-to-support order with real evidence/help, truthful peer stage and next step. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore Set and use Boolean flags with this free Grade 8 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

Closed answers are checked in your browser. Drawings and written explanations 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.

Book page references identify the related teaching topic. File-management and responsible-data preparation are original PaxaKids material; orientation or contents pages are not presented as teaching citations for those skills. 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.