Sign in

Intro to Computer Science / Unit 5: Conditionals and Boolean Logic

5.3 Logical Operators

3 practice questionsNot yet reviewed

Notes

Combine conditions with and, or and not.

  • A and B is True only if both are True.
  • A or B is True if at least one is True.
  • not A flips True to False and False to True.
  • Example: age >= 13 and age <= 18 is True for ages 13 through 18.
  • Evaluation order: not, then and, then or. Use parentheses to be clear.
  • Example: with x = 5, x > 2 and x < 4 is False, but x > 2 or x < 4 is True.

Practice

What does print(3 > 1 and 2 > 5) display?
What does print(not (4 == 4)) display?
Which condition is True when a number n is between 10 and 20, inclusive?

Ready for more? Take the Unit 5 test.