Computer Science
Grade 5
20 min
Logical Operators
Logical Operators
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define the three main logical operators: `and`, `or`, and `not`.
Predict the True/False outcome of a conditional statement using the `and` operator.
Predict the True/False outcome of a conditional statement using the `or` operator.
Use the `not` operator to reverse a Boolean value.
Write a simple Python `if` statement that combines two conditions using a logical operator.
Want to get into the secret treehouse? 🌳 You need to know the password AND be wearing the secret color. How does a computer check if both things are true at once?
In this lesson, you'll learn about special keywords called Logical Operators. These operators (`and`, `or`, `not`) let us combine simple True/False questions into more powerful ones, helping our programs make smarter decis...
2
Key Concepts & Vocabulary
TermDefinitionExample
Logical OperatorA special word used to connect or change True/False values (Booleans). The main ones are `and`, `or`, and `not`.In `(score > 10) and (level == 5)`, the word `and` is the logical operator.
BooleanA data type that can only have one of two values: `True` or `False`.The variable `is_sunny = True` holds a Boolean value.
andA logical operator that checks if BOTH conditions are `True`. The whole expression is only `True` if every part is `True`.`True and True` results in `True`. But `True and False` results in `False`.
orA logical operator that checks if AT LEAST ONE condition is `True`. The whole expression is `True` if one part (or both) is `True`.`True or False` results in `True`. Only `False or False` results in `False`.
notA logical operator that fli...
3
Core Syntax & Patterns
The 'and' Rule (The Strict Parent)
condition1 and condition2
Use `and` when you need multiple things to be true at the same time. Think of it as a strict rule: you must do this AND that. If even one part is False, the whole thing is False.
The 'or' Rule (The Easy-Going Friend)
condition1 or condition2
Use `or` when you only need one of several things to be true. Think of it as having a choice: you can do this OR that. As long as one part is True, the whole thing is True.
The 'not' Rule (The Opposite Day Rule)
not condition
Use `not` to check if something is False. It flips the value of the condition that follows it. It's useful for checking when something *isn't* happening.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
To get a discount, a person must be a club member AND have a coupon, OR they can just be a manager. Given `is_member = False`, `has_coupon = True`, and `is_manager = True`, what is the result of `(is_member and has_coupon) or is_manager`?
A.True
B.False
C.Error
D.Discount
Challenging
What will happen when this code is run? `result = (5 < 10) or (1 / 0 == 2)`
A.It will cause a ZeroDivisionError because you can't divide by zero.
B.The variable `result` will be `False`.
C.The variable `result` will be `True`, and no error will occur.
D.The variable `result` will be `None`.
Challenging
A program checks a condition and then tries to perform a calculation that would cause an error. What is the final output of this code?
`x = 10`
`if (x > 20) and (x / 0 > 5):`
`print('Calculated')`
`else:`
`print('Skipped')`
A.It will print 'Calculated'.
B.It will print 'Skipped'.
C.It will crash with a ZeroDivisionError.
D.It will print nothing.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free