Outline for October 11, 2022

Reading: §4, 6
Assignments: Homework 2, due October 20, 2022


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

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

  3. 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

  4. 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]

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

  6. String methods: methods that change, add, or delete characters do not alter the string to which they are applied; they return a new string that is a copy of the old string, suitably modified


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: [email protected]
MHI 289I, Programming in Health Informatics
Version of October 11, 2022 at 6:02PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh