Practice Logical Operators in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick 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.

Showing a random 20 of 50 problems.

Example 1

medium
Evaluate NOT (True OR False) AND True\text{NOT (True OR False) AND True} using precedence.

Example 2

easy
Evaluate: True AND True AND False\text{True AND True AND False}.

Example 3

medium
Access is granted if `(isAdmin OR isOwner) AND NOT isBanned`. For isAdmin=False, isOwner=True, isBanned=False, is access granted?

Example 4

hard
Show that A XOR B≡(A AND NOT B) OR (NOT A AND B)A \text{ XOR } B \equiv (A \text{ AND NOT } B) \text{ OR }(\text{NOT } A \text{ AND } B) by testing (A,B)=(T,F)(A,B) = (\text{T},\text{F}).

Example 5

medium
Evaluate (A AND B) OR (A AND NOT B)(A \text{ AND } B) \text{ OR } (A \text{ AND NOT } B) for A=A=True, B=B=False.

Example 6

challenge
XOR can be built from AND, OR, NOT. Verify that A XOR B=(A OR B) AND NOT(A AND B)A \text{ XOR } B = (A \text{ OR } B) \text{ AND NOT}(A \text{ AND } B) for A=True,B=TrueA=\text{True}, B=\text{True}.

Example 7

challenge
Write the negation of 'every student passed' using logical operators (formally).

Example 8

medium
How many rows are in the truth table for an expression with 5 boolean variables?

Example 9

hard
Simplify: (A AND B) OR (A AND NOT B)(A \text{ AND } B) \text{ OR }(A \text{ AND NOT } B).

Example 10

medium
Using De Morgan's law, rewrite NOT (A OR B)\text{NOT (A OR B)} without the outer NOT.

Example 11

medium
Evaluate A AND NOT B OR CA \text{ AND NOT } B \text{ OR } C for A=A=True, B=B=True, C=C=False, using standard precedence.

Example 12

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 13

easy
How many rows does the truth table for AA AND BB have?

Example 14

hard
Why is `{NAND}` (NOT AND) considered functionally complete on its own?

Example 15

hard
Three variables A,B,CA, B, C. Build a truth-table expression that is True only when EXACTLY one of them is true.

Example 16

medium
Identify the bug: `if (x = 0 OR 1 OR 2)` is meant to test whether x is 0, 1, or 2.

Example 17

medium
A short-circuit AND `A AND B` skips evaluating B when A is false. If A is `False`, is B evaluated?

Example 18

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?

Example 19

easy
Evaluate: NOT False\text{NOT False}.

Example 20

easy
Evaluate: NOT True\text{NOT True}.