Check your understanding of the previous reading: comparison operators, boolean operators, and how logic expressions evaluate.

Question 1

Identify whether each of these are True, False, or cause an error.
3 < 5
False
10 == 10.0
10 == "10"
5 == 5.5
7 != 7
3 < "5"
not False
1 < 2 and 5 < 7
5 < 4 or 3 == 3
True or (True and False)
not True and False

Question 2

How many values can each of these operators take?
<
not
and
!=

Question 3

Given the following code:

age = 0

are these two expressions equivalent?

age == 10 or 0
age == 10 or age == 0

Are the two expressions above equivalent?

Select one answer, then check.

  • Correct: they are not equivalent. Since age is 0, age == 10 is False, so age == 10 or 0 evaluates to 0 (the unevaluated second operand of or), not a boolean. Meanwhile age == 10 or age == 0 evaluates the second comparison explicitly and gives True. This mirrors the reading's own "Logic Expressions Are Not Distributive" section: you cannot distribute a comparison across an or/and the way you can with arithmetic. or 0 does not become or age == 0 for free.
  • Not quite: trace it. Since age is 0, age == 10 is False, so the first expression is False or 0, which evaluates to 0, not True/False as a comparison. The second expression evaluates age == 0 explicitly, giving True. The two produce different values, so they are not equivalent. See the reading's "Logic Expressions Are Not Distributive" section.