Outline for January 16
Reading
: Wentworth
et al.
, §4.1–4.4
Due
: Homework 1, due on January 18 at 11:55pm
Functions [
hello.py
]
What functions are
Defining them
Using them
Quick look at using functions [
quad.py
]
Passing values to functions
Returning values from functions
In more detail: passing values to functions [
args.py
]
Formal parameters in subject definition
Actual parameters (arguments)
Matching arguments to formal parameters
Local variables
In more detail: how Python does function calls [
quad.py
]
Caller suspends execution at point of call, remembers where it left off
Formal parameters assigned values from actual parameters
Execute function body
Return control to where caller left off
Refactoring code
Compute the perimeter of a triangle [
peri0.py
]
Collapse similar statements: make the distance between 2 points a function [
peri1.py
]
Collapse similar statements: make the prompts a function [
peri2.py
]
Refactor for clarity only: make the perimeter computation a function [
peri3.py
]
Now add error checking [
peri-c.py
]
Add error checking: “quad.py” done right [
quad-c.py
]
Matt Bishop
Office: 2209 Watershed Science
Phone: +1 (530) 752-8060
Email:
[email protected]
You can also obtain a PDF version of this.
Version of January 15, 2019 at 6:36PM