🔀 Making Decisions, lesson 4 of 5
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".
Example
Combining conditions
Set has_ticket = False and run it again.
Quiz
What does this print?
True True
False True
False False
True False
Example
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.
Exercise
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.
Quiz
What does this print?
True
False
15
Error