PencilCoder

Logic Ops!

Goals:

  • Code more complex Boolean expressions using logic operators

Coding Snippets:

  • coding snippets
  • and, or, and not are logic operators. Use them express more complex logic in a single expression.
  • Logic operators combine boolean values, i.e., variables or expressions that evaluate to true or false.

Math and Computer Concepts:

  • The expression a or b evaluates to true if either a is true or b is true (or both). The expression a and b evaluates to true if both a and b are true simultaneously.
  • not a gives the opposite of the boolean expression a. For example, not a evaluates to true if a is false.
  • Logic operators allow us to avoid using nested if statements, as illustrated by the following functionally equivalent snippets:

Activities:

Save each of the following in a folder called LogicOps.