GRADE 8 · COMPUTING · UNIT 1 · LESSON 1.23

Computational thinking and programming

Boolean operators in Python

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

Topic 1.23 · Boolean operators in Python10 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Boolean operators in Python

Combine Python comparisons with and, or and not. Preserve parentheses when they express the intended rule, and remember that equality on strings is case-sensitive unless you deliberately normalise input.

Today’s two goals
  • Use lowercase and, or and not with complete comparisons and trace their effect on selection.
  • Explain my method and support it with a labelled trace, example or test record.
Original PaxaKids illustration for Boolean operators in Python. 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

For colour = "Blue", colour == "blue" is False. Choosing colour.strip().lower() first would be an explicit input-normalisation policy, not an automatic feature of equality.

Try before your workbook

Is (x >= 3 and x <= 7) true when x = 7? Why?

Explore the clues

Tap one card to find out more.

Understand the idea

Combine Python comparisons with and, or and not. Preserve parentheses when they express the intended rule, and remember that equality on strings is case-sensitive unless you deliberately normalise input.

Concept to practise: Boolean operators in Python.

Work through an example

For colour = "Blue", colour == "blue" is False. Choosing colour.strip().lower() first would be an explicit input-normalisation policy, not an automatic feature of equality.

Try before your workbook

Is (x >= 3 and x <= 7) true when x = 7? Why?

Check my readiness thinking

Yes. Both comparisons are true at 7 because the upper comparison uses <=. Changing it to < would exclude 7.

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 complete conditions in Python

A fictional museum-room program can require two facts at once, accept either of two alternatives or reverse a test. Python uses lowercase and, or and not.

Comparisons such as group <= 8 or card == "yes" produce Boolean results. The Boolean operators combine or reverse those results. This lesson works with explicit True/False operands.

Complete the Boolean truth table

A and B below are Boolean values, not arbitrary strings or numbers. For or, either true operand is enough and both may also be true. For not A, only the value of A matters.
Complete the Boolean truth table — original model
ABA and BA or Bnot A
TrueTrue{'clue': 'True or False', 'prompt': 'True and True', 'answers': ['True']}{'clue': 'True or False', 'prompt': 'True or True', 'answers': ['True']}{'clue': 'True or False', 'prompt': 'not True with B True', 'answers': ['False']}
TrueFalse{'clue': 'True or False', 'prompt': 'True and False', 'answers': ['False']}{'clue': 'True or False', 'prompt': 'True or False', 'answers': ['True']}{'clue': 'True or False', 'prompt': 'not True with B False', 'answers': ['False']}
FalseTrue{'clue': 'True or False', 'prompt': 'False and True', 'answers': ['False']}{'clue': 'True or False', 'prompt': 'False or True', 'answers': ['True']}{'clue': 'True or False', 'prompt': 'not False with B True', 'answers': ['True']}
FalseFalse{'clue': 'True or False', 'prompt': 'False and False', 'answers': ['False']}{'clue': 'True or False', 'prompt': 'False or False', 'answers': ['False']}{'clue': 'True or False', 'prompt': 'not False with B False', 'answers': ['True']}

Read a complete not decision

This original program reads exact text. The comparison token == "blue" is grouped for clarity, then not reverses its result. Parentheses help readers see the grouping; Python does not require them around this simple comparison.
Original Paxa token comparison
token = input()
if not (token == "blue"):
    print("Different token")
else:
    print("Blue token")

Require two facts with and

Use a valid nonnegative integer group size followed by the card text on separate lines. The fictional policy allows the room only when the group has at most 8 people and the card is exactly yes. No automatic capitalisation change is present.
Original Paxa two-fact room policy
group = int(input())
card = input()
if group <= 8 and card == "yes":
    print("Use room")
else:
    print("Choose another room")

Trace both facts and their selected output

Use page 4. Complete True or False for the whole condition and then the exact branch message. Include the size boundary and a case difference.
Trace both facts and their selected output — original model
GroupCardWhole conditionOutput
7yes{'clue': 'True or False', 'prompt': 'Whole room condition for 7/yes', 'answers': ['True']}{'clue': 'Exact output', 'prompt': 'Room output for 7/yes', 'answers': ['Use room']}
8yes{'clue': 'True or False', 'prompt': 'Whole room condition for 8/yes', 'answers': ['True']}{'clue': 'Exact output', 'prompt': 'Room output for 8/yes', 'answers': ['Use room']}
9yes{'clue': 'True or False', 'prompt': 'Whole room condition for 9/yes', 'answers': ['False']}{'clue': 'Exact output', 'prompt': 'Room output for 9/yes', 'answers': ['Choose another room']}
7no{'clue': 'True or False', 'prompt': 'Whole room condition for 7/no', 'answers': ['False']}{'clue': 'Exact output', 'prompt': 'Room output for 7/no', 'answers': ['Choose another room']}
7YES{'clue': 'True or False', 'prompt': 'Whole room condition for 7/YES', 'answers': ['False']}{'clue': 'Exact output', 'prompt': 'Room output for 7/YES', 'answers': ['Choose another room']}

Accept agreed answer variants with or

The original riddle below accepts exactly three spellings: book, BOOK and Book. Each accepted string has its own equality comparison. The question prints before the selected feedback; entered text is not an output line.
Original Paxa reading riddle
print("I am a bound set of pages to read. What am I?")
answer = input()
if answer == "book" or answer == "BOOK" or answer == "Book":
    print("Match")
else:
    print("Try book")

Predict accepted and unmatched answers

Use page 6. Fill only Match or Try book for the feedback line. The question still prints first for every input.
Predict accepted and unmatched answers — original model
Entered answerFeedback
book{'clue': 'Match or Try book', 'prompt': 'Riddle feedback for book', 'answers': ['Match']}
Book{'clue': 'Match or Try book', 'prompt': 'Riddle feedback for Book', 'answers': ['Match']}
BOOK{'clue': 'Match or Try book', 'prompt': 'Riddle feedback for BOOK', 'answers': ['Match']}
a book{'clue': 'Match or Try book', 'prompt': 'Riddle feedback for a book', 'answers': ['Try book']}
books{'clue': 'Match or Try book', 'prompt': 'Riddle feedback for books', 'answers': ['Try book']}
pen{'clue': 'Match or Try book', 'prompt': 'Riddle feedback for pen', 'answers': ['Try book']}

Fix an incomplete comparison and extend the policy

The left example is an intentional bug: the nonempty string "BOOK" is treated as true, so even pen incorrectly selects Match. The right example uses full comparisons and adds exact a book and books. Parentheses let a long condition continue on the next line.
A: intentional bug
answer = input()
if answer == "book" or "BOOK":
    print("Match")
else:
    print("Try book")
B: correct extension
answer = input()
if (answer == "book"
        or answer == "BOOK"
        or answer == "Book"
        or answer == "a book"
        or answer == "books"):
    print("Match")
else:
    print("Try book")

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.

Boolean operators in Python10 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 10 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.3 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 10 worksheets

Worksheet 1

  1. Question 1: Which operator requires both Boolean operands to be true? and
  2. Question 2: Which operator reverses one Boolean result? not

Worksheet 2

  1. Question 3: True and True True
  2. Question 4: True or True True
  3. Question 5: not True with B True False
  4. Question 6: True and False False
  5. Question 7: True or False True
  6. Question 8: not True with B False False
  7. Question 9: False and True False
  8. Question 10: False or True True
  9. Question 11: not False with B True True
  10. Question 12: False and False False
  11. Question 13: False or False False
  12. Question 14: not False with B False True

Worksheet 3

  1. Question 15: What prints for exact blue? Blue token
  2. Question 16: What prints for Blue with a capital B? Different token
  3. Question 17: Which comparison has the same result as not (token == "blue")? token != "blue"

Worksheet 4

  1. Question 18: Does a group of 9 with yes satisfy the whole condition? no, the size comparison is false
  2. Question 19: Does a group of 7 with no satisfy the whole condition? no, the card comparison is false

Worksheet 5

  1. Question 20: Whole room condition for 7/yes True
  2. Question 21: Room output for 7/yes Use room
  3. Question 22: Whole room condition for 8/yes True
  4. Question 23: Room output for 8/yes Use room
  5. Question 24: Whole room condition for 9/yes False
  6. Question 25: Room output for 9/yes Choose another room
  7. Question 26: Whole room condition for 7/no False
  8. Question 27: Room output for 7/no Choose another room
  9. Question 28: Whole room condition for 7/YES False
  10. Question 29: Room output for 7/YES Choose another room

Worksheet 6

  1. Question 30: How many accepted strings are listed? three
  2. Question 31: Which comparison is repeated for each accepted variant? answer == the accepted string

Worksheet 7

  1. Question 32: Riddle feedback for book Match
  2. Question 33: Riddle feedback for Book Match
  3. Question 34: Riddle feedback for BOOK Match
  4. Question 35: Riddle feedback for a book Try book
  5. Question 36: Riddle feedback for books Try book
  6. Question 37: Riddle feedback for pen Try book

Worksheet 8

  1. Question 38: Which version correctly rejects pen? B
  2. Question 39: Which Boolean operator joins the allowed alternatives? or

Worksheet 9

  1. Question 40: Create a program for this fictional exhibit rule. Read a nonnegative integer group size, a pass colour and cancellation text yes or no. Print Entry only when the group is at most 8, the pass is exactly blue or green, and the visit is not cancelled. Otherwise print Wait. Use and, or and not with complete comparisons and clear grouping. Test (8, blue, no), (8, green, no), (9, blue, no), (7, red, no) and (7, blue, yes). Record predictions, actual output or Pending and explain each Boolean operator. Cite complete code and test records if saved. Complete three-input program, integer conversion and exact text policy. Condition equivalent to group <= 8 and (colour == "blue" or colour == "green") and not (cancelled == "yes"). Entry for first two tests, Wait for remaining three. Valid nonnegative integer and cancellation yes/no domain explicit; no unstated validation. Clear parentheses ensure pass alternatives grouped with required size/cancellation, full comparison each side of or, lowercase keywords/colon/four-space blocks. Explain all three operators, complete source and prediction/actual or Pending evidence, correction and retest if needed. No numerical marks or invented execution. Grown-up review; personal evidence is required.

Worksheet 10

  1. Question 41: Modify the page 6 riddle to accept all five exact forms shown in the correct page 8 extension. Then create a separate original riddle with at least two agreed answer forms and a defined nonmatch response. Write its question and accepted forms before coding. Identify comparison and Boolean operators, accepted-output and all-false fallback blocks. Test every agreed form and at least one wrong input in both programs. Record predicted and actual feedback or Pending, an actual correction if needed, and individual or genuine partner review. Cite full source and test records or attach complete code. Modified original accepts exactly book, BOOK, Book, a book, books; wrong pen rejected. Own riddle question/accepted forms explicit, at least two meaningful forms using complete equality comparisons joined by or, one accepted feedback and defined fallback. Lowercase Python, colon and consistent action blocks; grouping/continuation valid if used. Tests cover all accepted forms and at least one wrong input in each program, prediction/actual or Pending separated, comparison == distinguished from Boolean or, true/fallback annotation, truthful review and correction/retest if needed. Accept documented broader normalisation only as explicit policy change with appropriate tests. No fake partner or execution evidence. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore Boolean operators in Python 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.