Outline for January 14

Reading: Wentworth et al., §3
Due: Homework 1, due on January 18 at 11:55pm


  1. Curves in turtle
    1. Drawing parts of a circle [tcircle.py]
    2. Drawing a curve [tcurve.py]
  2. Why you don’t count with floating point numbers [roundoff.py]
  3. Simultaneous assignment [swap.py]
    1. Simple assignment: variable = expression
    2. Simultaneous assignment: variableA, variableB = expressionA, expressionB
  4. Decision structures
    1. If statement [if0.py]
    2. Executes once, based on condition
    3. Syntax
  5. Conditions
    1. Resolves to boolean value
    2. Literal booleans: True (1), False (0)
    3. Relational operators
      1. Use two arithmetic expressions connected with relational operatorsto create a boolean
      2. Relational operators: >, >=, <, <=, ==, !=
      3. Precedence: resolved after arithmetic operators
      4. Connectives: and, or, not
      5. 6 > 2 + 3; "UCD" == "Sac State"
  6. Two-way decisions [if1.py]
    1. if-else statements
    2. One condition, two possible code blocks
    3. else very powerful when the positive condition is easy to describe but not the negative
  7. 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. Nested if statements
  8. Indefinite loops: execute until a general condition is false (while)
    1. while [while.py]
    2. Contrast with for
    3. break causes program to fall out of loop (works with for too) [loop1.py]
    4. continue causes program to start loop over immediately (works with for too) [loop1.py]
  9. Definite loops: execute a specific (definite) number of times (for)
    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)
  10. 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
  11. Program: counting to 10 [toten.py]
  12. Program: sum the first 10 squares [sumsq.py]
  13. Program: Fibonacci numbers [fib.py]

UC Davis seal
Matt Bishop
Office: 2209 Watershed Science
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
You can also obtain a PDF version of this.
Version of January 13, 2019 at 11:11PM