Outline for October 4, 2021

Reading: §5.4, 6.11
Due: Homework 1, due October 6, 2021
Handouts: “Printing”

  1. Output [printing.py]
    1. Printing without format
    2. Printing with format using %
    3. Printing with format using format method

  2. continue and break statements in loops [loop1.py]

  3. import statement
    1. import math [hypotnoex.py]
    2. Need the “math.” before “sqrt”
    3. from math import sqrt [hypotnoex1.py]
    4. Do not need the “math.” before “sqrt”
    5. Now add in exception handling [hypotex.py]

  4. Full version of the hypotenuse program [pythag1.py]

  5. Exception ValueError — built-in function or operation applied to operator with illegal value

  6. Functions [hello.py]
    1. What functions are
    2. Defining them
    3. Using them

  7. Quick look at using them [quad.py]
    1. Passing values to functions
    2. Returning values from functions

  8. In more detail: passing values to functions [args.py]
    1. Formal parameters in subject definition
    2. Actual parameters (arguments)
    3. Matching arguments to formal parameters
    4. Local variables

  9. In more detail: how Python does function calls [quad.py]
    1. Caller suspends execution at point of call, remembers where it left off
    2. Formal parameters assigned values from actual parameters
    3. Execute function body
    4. Return control to where caller left off

  10. Refactoring code
    1. Compute the perimeter of a triangle [peri0.py]
    2. Collapse similar statements: make the distance between 2 points a function [peri1.py]
    3. Collapse similar statements: make the prompts a function [peri2.py]
    4. Refactor for clarity only: make the perimeter computation a function [peri3.py]
    5. Add error checking: “peri0.py” done right [peri-c.py]

  11. Add error checking: “quad.py” done right [quad-c.py]


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 235A, Computer and Information Security
Version of September 30, 2021 at 11:09AM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh