Outline for January 10, 2018

Reading: §2, 3


  1. Input
    1. input, raw_input
    2. try … except
  2. Simultaneous assignment [swap.py]
    1. Simple assignment: variable = expression
    2. Simultaneous assignment: variableA, variableB = expressionA, expressionB
  3. Decision structures [if0.py]
    1. If statement
    2. Executes once, based on condition
    3. Syntax
  4. Conditions
    1. Resolves to boolean value
    2. Literal booleans: True (1), False (0)
    3. Testable as true or false
    4. Relational operators
      1. Use two arithmetic expressions connected with relational operators to create a boolean
      2. Relational operators: >, >=, <, <=, ==, !=
      3. Precedence: resolved after arithmetic operators
      4. 6 > 2 + 3; "UCD" == "Sac State"
  5. Two-way decisions [if1.py]
    1. if … else statements
    2. One condition, two possible code blocks
    3. Syntax
    4. else very powerful when the positive condition is easy to describe but not the negative
    5. String comparison example
  6. . Multi-way decisions [if2.py]
    1. Can execute code based on several conditions
    2. elif (else if)
    3. Syntax
    4. else only reached if all previous conditions false
    5. Nested if statements

Matt Bishop
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562 USA
Last modified: January 10, 2018
Winter Quarter 2018
You can get a PDF version of this