Logical Operators Examples: 47 Problems with Answers
Start with the recap, study the fully worked examples, then use the practice problems to
check your understanding of Logical Operators.
This page combines explanation, solved examples, and follow-up practice so you can move
from recognition to confident problem-solving in CS Thinking.
Concept Recap
Operators that combine or modify boolean expressions: AND (true only when both operands are true), OR (true when at least one operand is true), and NOT (reverses a boolean value from true to false or vice versa).
AND is strict (both must be true), OR is flexible (either works), NOT flips the result.
Read the first worked example with the solution open so the structure is clear.
Try the practice problems before revealing each solution.
Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea:Logical operators let you build complex conditions from simple boolean tests.
Common stuck point:AND requires ALL conditions true; OR only requires ONE — easy to confuse.
Sense of Study hint:When combining conditions with AND/OR, evaluate each condition separately first, then combine. Remember: AND narrows results (both must be true), OR broadens results (either suffices). Use parentheses to make the order of evaluation explicit.
Worked Examples
Example 1
medium
Evaluate A AND NOT B OR C for A=True, B=True, C=False, using standard precedence.
Answer
False
First step
1
NOT B = NOT True = False.
See the full worked solution + why-it-works coaching
Setup·Key insight·Why it works·Common pitfall·Connection
Identify the bug: `if (x = 0 OR 1 OR 2)` is meant to test whether x is 0, 1, or 2.
Example 4
hard
Simplify A OR (A AND B) using boolean algebra.
Example 5
hard
Simplify the condition: `NOT (age < 13 OR age > 65)`.
Example 6
challenge
A condition `(NOT a) OR (NOT b)` is being optimized. Show two equivalent simpler forms.
Practice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
easy
Evaluate: True AND False.AND truth table — highlighted row shows True AND False.
Example 2
easy
Evaluate: True OR False.OR truth table — highlighted row shows True OR False.
Example 3
easy
Evaluate: NOT True.
Example 4
easy
Evaluate: True XOR True (XOR is true when operands differ).XOR truth table — highlighted row shows True XOR True.
Example 5
easy
Evaluate: False OR False.OR truth table — highlighted row shows False OR False.
Example 6
easy
Evaluate: True AND True.AND truth table — highlighted row shows True AND True.
Example 7
easy
Evaluate: NOT (False).
Example 8
easy
In `x == 5 OR 10`, why is this a logic bug when checking if x is 5 or 10?
Example 9
medium
Evaluate NOT True AND False using precedence (NOT before AND).Evaluating NOT True AND False step by step (NOT binds first).
Example 10
medium
Evaluate True OR False AND False using precedence (AND before OR).Evaluating True OR False AND False step by step (AND binds first).
Example 11
medium
Using De Morgan's law, rewrite NOT (A AND B) without the outer NOT.
Example 12
medium
Using De Morgan's law, rewrite NOT (A OR B) without the outer NOT.
Example 13
medium
A short-circuit AND `A AND B` skips evaluating B when A is false. If A is `False`, is B evaluated?
Example 14
medium
Evaluate (True AND False) OR (NOT False).Evaluating (True AND False) OR (NOT False) in three steps.
Example 15
medium
For a discount, a customer needs (age over 65) OR (student AND member). If age=70, student=False, member=False, does the customer qualify?Discount condition: (age > 65) OR (student AND member) with age=70, student=False, member=False.
Example 16
challenge
Simplify NOT(NOT A OR NOT B) using De Morgan and double negation.
Example 17
challenge
XOR can be built from AND, OR, NOT. Verify that A XOR B=(A OR B) AND NOT(A AND B) for A=True,B=True.
Example 18
challenge
A condition `NOT (x > 0 AND x < 10)` should reject values inside (0,10). Rewrite it with De Morgan into an OR of comparisons.
Example 19
medium
Evaluate NOT (True OR False) AND True using precedence.
Example 20
medium
Access is granted if `(isAdmin OR isOwner) AND NOT isBanned`. For isAdmin=False, isOwner=True, isBanned=False, is access granted?(isAdmin OR isOwner) AND NOT isBanned with isAdmin=F, isOwner=T, isBanned=F.
Example 21
easy
Evaluate: False AND True.AND truth table — highlighted row shows False AND True.
Example 22
easy
Evaluate: False OR True.OR truth table — highlighted row shows False OR True.
Example 23
easy
Evaluate: True XOR False (XOR is true when operands differ).XOR truth table — highlighted row shows True XOR False.
Example 24
easy
How many rows does the truth table for A AND B have?Complete truth table for A AND B — count the rows to answer the question.
Example 25
easy
Which operator binds TIGHTEST (highest precedence): AND, OR, or NOT?
Example 26
easy
Evaluate: True AND True AND False.Evaluating True AND True AND False left to right.
Example 27
medium
Evaluate NOT(True AND False) OR False using precedence.Evaluating NOT(True AND False) OR False in three steps.
Example 28
medium
Rewrite NOT(x=5) without NOT, using a comparison.
Example 29
medium
A discount is given if (member AND age >= 18) OR (employee). Are member=False, age=25, employee=True eligible?(member AND age >= 18) OR employee with member=F, age=25, employee=T.
Example 30
medium
Short-circuit OR: in `A OR B`, B is skipped if A is True. If A=True and B is `1/0`, does the expression crash?
Example 31
medium
Evaluate (A AND B) OR (A AND NOT B) for A=True, B=False.
Example 32
medium
The expression A AND NOT A is what kind of formula?
Example 33
medium
Access if `loggedIn AND (isAdmin OR isOwner)`. For loggedIn=True, isAdmin=False, isOwner=False, is access granted?loggedIn AND (isAdmin OR isOwner) with loggedIn=T, isAdmin=F, isOwner=F.
Example 34
medium
If short-circuit AND is used and `A AND B` evaluates only A when A is False, what design rule does this enable?
Example 35
hard
Simplify A AND (A OR B) using boolean algebra.
Example 36
hard
Show that A XOR B≡(A AND NOT B) OR (NOT A AND B) by testing (A,B)=(T,F).
Example 37
hard
Three variables A,B,C. Build a truth-table expression that is True only when EXACTLY one of them is true.
Example 38
hard
Why is `{NAND}` (NOT AND) considered functionally complete on its own?
Example 39
hard
Simplify: (A AND B) OR (A AND NOT B).
Example 40
challenge
A short-circuit AND in `expensiveCheck() AND cheapCheck()` runs the expensive one first. What is the smell, and the fix?
Example 41
challenge
Write the negation of 'every student passed' using logical operators (formally).