DLT:
  • Use Python commands to solve puzzle modules
  • Use conditionals to detect whether a condition is true and only run code in certain cases
  • Use assignment operators to change the value of a variable
  • Use comparison operators to compare values
  • Use logical operators to check multiple conditions at the same time or reverse the value of a boolean
  • Distinguish between assignment, comparison, and logical operators

Vocabulary:
  • Boolean: A boolean is a data type that has only two possible values: True or False. These two values can correspond to a lot of meanings, such as on or off. Comparison or equality testing statements (such as x > 4) evaluate to a boolean because x is either greater than 4 (true) or not greater than 4 (false).
  • Conditional Statement: A conditional statement checks if a condition is true and then only executes code if the condition is true. Examples of conditional statements are "if" statements, "if-else" statements, and "if-elif-else" statements. Here is what the syntax looks like:
      • "if" statements:


      • "if-else" statements:


      • "if-elif-else" statements:


  • Assignment Operator: Assignment operators assign a value on the right side of the operator to the left side of the operator. When you’re using an assignment operator, it will only modify the value on the left side of the operator. These are shortcuts for assignments that could be written out in a slightly longer way. For example, you can use the assignment operator *= to assign the value of x * y to x (x *= y). However, you could also write this out as x = x * y.
  • Comparison Operator: Comparison operators check the values or expressions on the left and right side of the operator and return a boolean value of true or false based on the comparison. For example, you can check if x is equal to y (x == y), if x is not equal to y (x != y), or whether x is less than y (x < y).
  • Logical Operator: Logical operators take one or two boolean values and return a boolean value. For example, they can check if both are true (and) or if either is true (or). The logical not operator (not) returns the opposite of a boolean value.
  • Nested Conditional: You can add conditionals within conditionals. This is helpful if you want to check two conditions.

Activity:
  • Tynker Python: Conditional Logic - In this lesson, you will experiment with conditional statements, which you can use to programmatically make decisions based on one or more conditions or variables in the program. The operators you learn allow them to perform calculations and check conditions. Due by the end of class.
    • has_path_right() Returns true if there is a path to the right. Otherwise, it returns false.
    • has_path_left() Returns true if there is a path to the left. Otherwise, it returns false.
    • enemy_in_sight() Returns true if an enemy is within a distance of 5 units of the Actor's line of sight.
    • is_gap_ahead() Returns true if there is a jumpable gap ahead.