CoursesAIMathCodePhysicsAbout and FAQ

TwiddleLab / Code / Build with Python

And, Or, Not

Lesson 4 of 12 · 7 min · Free, no account needed

What you will learn

  • a and b is True only when both are True.
  • a or b is True when at least one is True.
  • not a flips True and False.
  • and is the overlap of two circles, or is everything inside either. Python does and before or.

Start the lesson

How the lesson goes

  1. Three tries to get the password right. Then the door should lock.

    This door has one condition. Try some wrong passwords.

  2. One word joins the two conditions. Which one?

    Keep asking while there are tries left ___ the guess is still wrong.

  3. Each condition is a lamp: lit means True.

    Flip the lamps and switch the word. Does the loop ask again? Fill all 8 cells.

  4. and, or, not.

    and: True only when both sides are True. or: True when at least one side is True.

    not flips one condition: not tries < 3 is True when tries is 3 or more.

    Python works out not first, then and, then or, like times before plus. A truth table lists every case.

  5. Drop each condition on the lamp it lights.

    Use the values in the boxes.

  6. You're the bouncer. Build the door rule.

    Pick the three parts, open the door, see who got in. Every call must be right.

  7. and and or as circles.

    Shade the parts of the picture where the rule is True, then check. Your guests will land in their spots.

  8. The right password, and the door still asks again. Fix it.

    Run it: the test types fox42 first. Then fix one word.

  9. The door from the start, and yours.

    Send both the same 5 wrong guesses. Then tap the door you'd trust.

Previous lesson: While: Until It's Done · Next lesson: Loops Inside Loops · Part of the course: Build with Python

Lessons are interactive and need JavaScript. Turn it on to play them.

Loading TwiddleLab