We now create our own functions. Using the terminology from our supplemental textbook, we refer to a function that produces (returns) a value as a "fruitful function"; we refer to a function that performs a task but does not return a value (e.,g., draws a graph) as a "procedure." Note that generally, the term function refers to both procedures and fruitful functions. In addition to defining functions, we will draw diagrams to visualize how they execute.
Note: Alternative links to watch the pre-lecture videos were added below on 2/17. If the original links performed poorly (e.g., slow loading) for your locale, try the alternative links.
importthe module. (Alternative Link)
returnstatement. We emphasize the difference between printing a value and returning a value. (Alternative Link)
The modules shown in the above videos are here. You can download the file to follow along, but it's ok not to. We will have additional examples during lecture.
Optional reading: 3.4 - 3.11 (html version)
Answers to the 6 questions at the end of the lecture slides (slides 50, 57, 59, 61, 63, 65): Do those visualization exercises to check your understanding of this lecture! See the lecture slides file above for the questions. After drawing the diagrams yourself, you can check your answers here.