Combining conditions in code

About this lesson: Combining conditions in code

In short

Python uses the words and, or, not to combine conditions. With and, both parts must be True. The door opens only with enough points and the key.

Combining conditions in code

What you'll explore

and: Both must be True
Python uses the words and, or, not to combine conditions. With and, both parts must be True. The door opens only with enough points and the key.
or: Either one will do
With or, the result is True if at least one part is True. Each side of or needs its own full comparison: day == "Sat" or day == "Sun". Change the day.
not: Flip it
not turns True into False and False into True. Games often keep looping while not game_over. End the game and see what happens.
Testing: Try every combination
To test a combined condition, choose inputs that make each part True and False. Run all four tests for the door.
Check yourself: Spot the bug
A program says: if colour == "red" or "blue": print("Team A"). It prints Team A for every colour.

Also in this lesson

  • Common mix-ups
  • and, or, not in Python
  • Combined conditions in real games
  • Truth table test

Words to know

and
True only if both conditions are True.
or
True if at least one condition is True.
not
Flips True and False.
compound condition
Two or more conditions joined with and/or.
test case
One set of inputs with its expected result.

Sources

  • Python documentation: Boolean operations

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 5 short steps and a 6-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 11 November 2026.

← Data types and constants · Using libraries →

All lessons in Term 3 · Computing · Age 12