2.3 - Logical Operators
2.3 - Logical Operators
2.3 - Logical Operators
Logical Operators
ICS 3U0
Today’s Agenda
1. Canadian citizen.
2. At least 18 years old.
For example: "I like movies that have action and comedy“. To
a computer, this person only likes movies that include both
action and comedy
(movie == action) and (movie == comedy)
AND Examples
Example 1:
1 < 2 and 5 > 3
(1 < 2) is TRUE, (5 > 3) is TRUE, so overall the
statement evaluates to TRUE What does this
mean? Evaluates
to true? Evaluates
Example 2: to false?
Write the code for this ... which logical operator would you
use?
• int
• float
• string
• boolean
Boolean DataType
Boolean variables are assigned one of two values
• Either a boolean variable is True
• Or a boolean variable is False
Example:
bad_num = False
if not bad_num:
print("Hey, you're a good number!")
Exercises – Logical Operators