These questions follow Boolean Logic. Every one of them can be settled by typing it into Python — but predict first, because the whole point is to make your prediction match the machine.

Working it out

  1. Give the value of each: True and False, True or False, not True, (5 > 3) and (2 > 4).
  2. With on_roster = True and form_returned = False, what does each of these produce?
    on_roster and form_returned
    on_roster or form_returned
    not (on_roster and form_returned)
  3. Complete the row: if A is False and B is True, then A and B is ___, A or B is ___, and not A is ___.
  4. Are not (A and B) and (not A) or (not B) the same for all four combinations of A and B? Show your reasoning.

Using it

  1. Find the fault. It is Monday, and this prints Weekend!
    day = "Mon"
    if day == "Sat" or "Sun":
        print("Weekend!")
  2. Why does this print False rather than crashing, when sessions is 0?
    print(sessions > 0 and minutes / sessions > 30)
  3. Write one condition for: the book is overdue and it has not been renewed. Then give the two variables names that make the line read like the sentence.
  4. Challenge. A student can go on the trip if they are 18 or older, or if a guardian has given permission. Write the condition, then explain why or is right here and and would be cruel.

Answers