Boolean Examples in CS Thinking

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Boolean.

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

A data type representing a logical value that can only be true or false—nothing else.

A boolean is a yes/no answer. Is the user logged in? True or false. Is the number positive? True or false.

Read the full concept explanation →

How to Use These Examples

  • 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: 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.

Worked Examples

Example 1

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

Solution

  1. 1
    Step 1: Substitute x = 7 into each comparison.
  2. 2
    Step 2: Evaluate (a) 7 > 5 \to TRUE and (b) 7 == 10 \to FALSE.
  3. 3
    Step 3: Evaluate (c) 7 != 7 \to FALSE and (d) 7 >= 7 \to TRUE.

Answer

(a) TRUE, (b) FALSE, (c) FALSE, (d) 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.

Practice Problems

Try these problems on your own first, 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?

Background Knowledge

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

assignmentdata types