Boolean Examples: 46 Problems with Answers

Worked examples of Boolean to try before you open each solution, then practice problems with answers.

Worked Examples

Example 1

easy
Evaluate each expression when x = 7: (a) x > 5, (b) x == 10, (c) x != 7, (d) x >= 7.
Show solution

Answer

(a) TRUE, (b) FALSE, (c) FALSE, (d) TRUE.

First step

1.
Step 1: Substitute x=7 into each comparison.

Full solution

  1. 2.
    Step 2: Evaluate (a) 7>5→ TRUE and (b) 7==10→ FALSE.
  2. 3.
    Step 3: Evaluate (c) 7!=7→ FALSE and (d) 7>=7→ TRUE.
Boolean expressions evaluate to TRUE or FALSE. They are the foundation of conditions in IF statements, loops, and filters. The operators >, <, ==, !=, >=, <= compare values.

Example 2

medium
A variable `isLoggedIn` is a boolean. Write pseudocode that outputs 'Welcome back' if logged in, or 'Please log in' otherwise.

Example 3

medium
A pseudocode block reads: IF age >= 13 AND age <= 19 THEN print 'teenager'. For age = 12, does it print?

Example 4

medium
A student writes `if score = 90:` in Python instead of `if score == 90:`. What goes wrong?

Example 5

medium
A coupon condition: total >= 50 AND (memberSince < 2020 OR isStudent). For total=60, memberSince=2022, isStudent=True, does the coupon apply?

Example 6

hard
Trace: x = 0; if x or 'no value': print('ran'); does it print?

Example 7

hard
Trace: nums = [0, 1, 2]; any(nums) returns?

Practice Problems

Try each one, then open the solution to compare your method.

Example 1

easy
What is the value of each: (a) NOT TRUE, (b) (5 < 3) OR (10 > 8), (c) (4 == 4) AND (3 > 5)?

Example 2

medium
A theme park ride requires: age ≥ 12 AND height ≥ 140. A child is age 13 and height 135. Evaluate the full Boolean expression step by step. Can they ride?

Example 3

easy
Evaluate `True AND False`.

Example 4

easy
Evaluate `True OR False`.

Example 5

easy
Evaluate `NOT True`.

Example 6

easy
Evaluate the comparison `5 > 3`.

Example 7

easy
Evaluate `4 == 4`.

Example 8

easy
Evaluate `7 != 7` (not-equal).

Example 9

easy
Evaluate `False OR False`.

Example 10

easy
Evaluate `NOT (3 < 2)`.

Example 11

medium
Evaluate `(5 > 3) AND (2 == 2)`.

Example 12

medium
Evaluate `(4 < 2) OR (6 >= 6)`.

Example 13

medium
Apply De Morgan: simplify `NOT (A AND B)`.

Example 14

medium
Evaluate XOR: `True XOR True` (true when operands differ).

Example 15

medium
Short-circuit: in `False AND f()`, is `f()` called? Why?

Example 16

medium
Truthy/falsy: in `if 0:` does the body run? What about `if "hi":`?

Example 17

medium
Style: rewrite `if x == True:` to use `x` directly. What is the cleaner form?

Example 18

medium
Evaluate `NOT True OR False` given NOT binds tighter than OR.

Example 19

medium
Evaluate `(3 == 3) AND (4 > 5) OR (1 < 2)` (AND before OR).

Example 20

challenge
Evaluate `NOT (A OR B)` when `A = False`, `B = True`, then verify with De Morgan.

Example 21

challenge
Short-circuit safety: explain why `if x != 0 AND 10 / x > 1:` ordering matters.

Example 22

challenge
Build a truth table count: for how many of the 4 input pairs (A,B) is `A XOR B` True?

Example 23

easy
What are the only two values a boolean variable can hold?

Example 24

easy
Evaluate when x = 10: x < 20.

Example 25

easy
Evaluate when n = 5: n != 5.

Example 26

easy
Evaluate: (8 >= 8).

Example 27

easy
What boolean value does the expression 3 > 5 produce?

Example 28

easy
Evaluate `NOT (5 == 5)`.

Example 29

medium
Evaluate when a=4, b=7: (a < b) AND (b < 10).

Example 30

medium
In Python, what does `bool([])` return?

Example 31

medium
In Python, what does `bool('False')` return?

Example 32

medium
Pseudocode: WHILE NOT done DO …. If done starts as True, how many times does the body run?

Example 33

medium
Evaluate (3 < x) AND (x < 10) when x = 3.

Example 34

medium
Evaluate (True AND False) OR (True AND True).

Example 35

medium
In Python, what does `(False or 7)` evaluate to?

Example 36

hard
What does Python print: `print(True + True + False)`?

Example 37

hard
A function returns the boolean `n > 0 and n % 2 == 0`. For n = -4, what does it return?

Example 38

hard
A login pseudocode: ok = (user == 'admin') AND (password == 'pw1'). Why is testing `if ok == True:` worse style than `if ok:`?

Example 39

challenge
In Python, what does `not '' and 'hi'` evaluate to?

What to focus on

Core idea: Booleans are the language of decisions. Every if-statement evaluates a boolean condition.

Common stuck point: 0, empty string, None/null, and empty lists are often 'falsy' — they act like False in conditions even though they're not boolean.

Ask yourself: Can the value only be yes or no, or is it the result of a comparison that an if or while will read?

Concept recap

A data type representing a logical value that can only be true or false—nothing else. Booleans are produced by comparison operators (==, <, >, !=) and consumed by control structures (if-statements, while-loops) to make decisions.

A checkbox on a form is a boolean: ticked or empty, with no third state, and anyone can read it later without asking the question again. A comparison like age >= 13 is the person deciding whether to tick it; the if statement is the office that reads the box. The picture stops at Python's truthy values, where 0 or empty text also counts as an empty box.

Read the full lesson on Boolean

Background knowledge

These ideas may be useful before you work through the harder examples.

assignmentdata types