🐍
PYTHON QUESTAgent Academy
0 XP
150 XP to Next Rank
Mission #4

🔐Lesson 4: Logic and Secret Passwords

Unlock secret doors using and, or, and not!

Lesson 4: Logic and Secret Passwords

Sometimes you need to verify two or three things at the exact same time: to enter a secret base, you need the password AND the keycard! Python gives us three special logic words: and, or, and not.

Key Concepts to Remember:

  • •
    and (Both must be True!): Both sides must be correct. If even one side is False, the whole test fails.
  • •
    or (At least one must be True!): If either the left OR right side is True, you win! It only fails if both sides are False.
  • •
    not (The Inverter): Flips True to False, and False to True. For example, not is_raining means it is sunny.

💻Guarding the Vault Example (IDE Syntax Colors)

has_key = True
knows_pin = True
 
if has_key and knows_pin:
print("🔓 Vault opened! Diamond secured!")
else:
print("🔒 Alarm triggered! Access denied!")

💡 Since both has_key and knows_pin are True, the and condition succeeds.

💡 Pro Tip: and is strict like a bouncer (demanding both items), while or is friendly (happy with either one).