Outline for April 29, 2009

Reading: §7.1–7.3 Guest Lecturer: Justin Cummins

  1. Decision structures
    1. If statement
    2. Executes once, based on condition
    3. Syntax (added condition to superkondit.py)
  2. Conditions
    1. Resolves to boolean value
    2. Literal booleans: True, False
    3. Testable as true or false
    4. d. Relational operators (extended condition in superkondit.py)
      1. Use two arithmetic expressions to create a boolean
      2. >, >=, <, <=, ==, !=
      3. Resolved after arithmetic operators
      4. 6 < 2; "UCD" == "Sac State"
      5. Python allows all sorts of comparison (even confusing ones)
  3. 3. Two-way decisions
    1. If-else statements
    2. One condition, two possible code blocks
    3. Syntax (extended superkondit.py)
    4. Else very powerful when the positive condition is easy to describe but not the negative
    5. String comparison example (see bad_login.py)
  4. 4. Multi-way decisions
    1. Can execute code based on several conditions
    2. elif (else if) introduced
    3. Syntax (extended superkondit.py)
    4. elif only reached if all previous conditions false