Boolean CS Thinking Example 1
Follow the full solution, then compare it with the other examples linked below.
Example 1
easyEvaluate each expression when x = 7: (a) x > 5, (b) x == 10, (c) x != 7, (d) x >= 7.
Solution
- 1 Step 1: Substitute into each comparison.
- 2 Step 2: Evaluate (a) TRUE and (b) FALSE.
- 3 Step 3: Evaluate (c) FALSE and (d) 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.
About Boolean
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.
Learn more about Boolean βMore Boolean Examples
Example 2 medium
A variable `isLoggedIn` is a boolean. Write pseudocode that outputs 'Welcome back' if logged in, or
Example 3 easyWhat is the value of each: (a) NOT TRUE, (b) (5 < 3) OR (10 > 8), (c) (4 == 4) AND (3 > 5)?
Example 4 mediumA theme park ride requires: age β₯ 12 AND height β₯ 140. A child is age 13 and height 135. Evaluate th