🔀 Making Decisions, lesson 4 of 6
and, or, not
Combine conditions with logical operators.
9 min
1 exercise
2 quizzes
0/3 solved
Getting Python ready… examples can run in a moment.
Logical operators combine booleans:
a and bisTrueonly if both are truea or bisTrueif at least one is truenot aflipsTruetoFalseand back
and is evaluated before or, so add parentheses
when you mix them. Python also lets you chain
comparisons: 13 <= age <= 19 means "age is between
13 and 19".
Truth table
Two booleans a and b can only be combined in these four ways. Let's work out each operator for every row.
Combining conditions
Set has_ticket = False and run it again.
What does this print?
Using them in if
Storing a condition in a well-named variable
(weekend) makes the if read like English. Set
raining = True and run it again.
Theme park rules
A ride requires a height of at least 120 cm and an
age of at least 8. Set can_ride to a single
boolean expression using and.
What does this print?