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 boolean is a yes/no answer. Is the user logged in? True or false. Is the number positive? True or false.
Showing a random 20 of 50 problems.
Example 1
easy
Evaluate: (8 >= 8).
Example 2
easy
Evaluate each expression when x = 7: (a) x > 5, (b) x == 10, (c) x != 7, (d) x >= 7.Evaluate each comparison when x = 7
Example 3
easy
Which operator tests equality (two equals signs)?
Example 4
easy
What boolean value does the expression 3 > 5 produce?
Example 5
medium
Evaluate `NOT True OR False` given NOT binds tighter than OR.
Example 6
medium
Evaluate when a=4, b=7: (a < b) AND (b < 10).
Example 7
hard
Trace: nums = [0, 1, 2]; any(nums) returns?
Example 8
challenge
Short-circuit safety: explain why `if x != 0 AND 10 / x > 1:` ordering matters.
Example 9
medium
Truthy/falsy: in `if 0:` does the body run? What about `if "hi":`?
Example 10
easy
Evaluate when n = 5: n != 5.
Example 11
medium
A coupon condition: total >= 50 AND (memberSince < 2020 OR isStudent). For total=60, memberSince=2022, isStudent=True, does the coupon apply?
Example 12
medium
Pseudocode: WHILE NOT done DO β¦. If done starts as True, how many times does the body run?
Example 13
medium
Apply De Morgan: simplify `NOT (A AND B)`.
Example 14
medium
Style: rewrite `if x == True:` to use `x` directly. What is the cleaner form?
Example 15
hard
What does Python print: `print(True + True + False)`?
Example 16
easy
Evaluate `NOT (3 < 2)`.
Example 17
easy
Evaluate when x = 10: x < 20.
Example 18
easy
Evaluate `True AND False`.AND truth table β highlighted cell: True AND False
Example 19
medium
Evaluate (True AND False) OR (True AND True).(True AND False) OR (True AND True) β step-by-step
Example 20
easy
In Python, the boolean values are written as ____ and ____.