Outline for October 13, 2020

Reading: §3, 5
Due: Homework 1, due October 15, 2020


  1. Simultaneous assignment [swap.py]
    1. Simple assignment: variable = expression
    2. Simultaneous assignment: variableA, variableB = expressionA, expressionB

  2. Decision structures [if0.py]
    1. If statement

  3. Conditions
    1. Resolves to boolean value
    2. Literal booleans: True, False
    3. 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"

  4. Two-way decisions [if1.py]
    1. if … else statements
    2. else very powerful when the positive condition is easy to describe but not the negative

  5. Multi-way decisions [if2.py]
    1. Can execute code based on several conditions
    2. elif (else if)
    3. else only reached if all previous conditions false
    4. Compare to nested if statements

  6. Iteration
    1. Definite loops: execute a specific (definite) number of times
    2. Indefinite loops: execute until a general condition is false

  7. For loops
    1. General form: for i in iterator
    2. Iterator is either list or something that generates a list
    3. Very common form: for i in range(1, 10)

  8. range() in detail [for.py]
    1. range(10) gives 0 1 2 3 4 5 6 7 8 9
    2. range(3, 10) gives 3 4 5 6 7 8 9
    3. range(2, 10, 3) gives 2 5 8
    4. range(10, 2, -3) gives 10 7 4

  9. While loops [while.py]
    1. Repeats until condition is false


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
MHI 289I, Programming for Health Informatics
Version of October 12, 2020 at 4:15PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh