S11 · Require Both Keys

What we learned in Python

The Python from session S11, one idea at a time. The same notes are in your course folder as lessons/sessions/s11/student/python-notes.md.

Back to the S11 slides

1 · Python concept

The idea

Today's Python
Boolean ANDand is True only when both Boolean inputs are True.
two Boolean parametersfirst_on and second_on receive the two key states independently.
truth tableFour rows cover every pair: FF → False, FT → False, TF → False, TT → True.

2 · Code we wrote

The code

def both_keys(first_on, second_on):
    return first_on and second_on


print(both_keys(False, False))
print(both_keys(False, True))
print(both_keys(True, False))
print(both_keys(True, True))

Run it from the course folder:

python lessons/sessions/s11/student/starter.py

Output:

False
False
False
True

3 · What the code means

Line by line

Each important line
def both_keys(first_on, second_on):Defines a function receiving the Sun Key and Moon Key states.
return first_on and second_onReturns True only when both keys are on. Either False input makes the result False.
both_keys(False, False)Neither key is on: False.
both_keys(False, True)Only the second key is on: False.
both_keys(True, False)Only the first key is on: False. This case exposes the starter bug.
both_keys(True, True)Both keys are on: True.

4 · Why programmers use this

Beyond this lesson

Predict every row before running the starter or opening AI help. Compare observed output with your predictions, repair one return expression, and rerun all four cases.

Programs use AND when all conditions must hold, such as having a ticket and an open entrance. One successful condition alone is insufficient.

Local Python models the rule. Validated YAML lists the two toggle IDs and the Vault Keeper's fallback and success responses. Trail owns actual key states and never imports or executes student Python. Every launch starts fresh.

In Twin Star Vault, M10 · Unlock the Secret (require-all-switches-on) completes only after both response branches display. Turning both keys on alone does not complete the mission.

5 · What we debugged

A bug worth understanding

return first_on
True, False returns True in the starter, but the both-keys rule requires False.

The starter ignores second_on. Change only the return expression to combine both inputs with and; do not add an if/else. Recheck all four rows.

Fixed:

return first_on and second_on

6 · Key Python words

Words to know

Vocabulary
BooleanOne of two values: True or False.
andRequires both conditions to be True.
parameterA named input to a function.
truth tableA complete list of input combinations and their expected results.

7 · Try it yourself

Your turn

  1. Write FF, FT, TF, and TT predictions and explain each before execution. Run the starter, identify the first mismatch, repair it, and compare all four repaired outputs.
  2. Validate and launch the task-card Trail. Hear the Vault Keeper with one or both keys off, then turn both keys on and speak again. Keep evidence of both responses and Responses 2 / 2.
  3. The fallback line is the same when one key or both keys are off. Use the truth table to explain what must change. Personalize response messages while keeping field names, IDs, and the two-toggle rule.
  4. Record your original prediction, actual result, tested revision, and why the check protects the rule. Explain accepted code in your own words.