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.

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