Reading¶
(3-4h) Reading PDF.
Until p.340, not including Programming exercises.
Concepts:
1. Intro
Meaning: group of statements for performing a specific task
void vs value-returning
2. Defining and calling a void function
function definition
rules for function names
calling a function
returning of a function
indentation
3. Designing a program to use functions
flowchart symbol
Top-down design
Placeholder functions and
passfor empty functions
4. Local variables
Scope
Different functions can have the same variable
5. Passing arguments to Functions
Multiple arguments
Making changes to an argument inside a function (assignment)
keyword arguments
order of arguments when mixing keyword arguments with positional ones
keyword-only parameters
positional-only parameters
default arguments
6. Global variables and global constants
7. Intro to value-returning functions: generating random numbers
Standard library functions and
importGenerating random numbers,
random.randint()Calling functions from an f-string
Generating random numbers in
ipython(I use it to generate random numbers during an oral exam 🙂, but use a different seed each time. Otherwise you get the same sequence, e.g.,import random as r; r.seed(); r.randrange(1, 12))Using random numbers to represent other values using
randint(BEGIN,END) == BEGINrandrange,random,uniformrandom number seeds
8. Writing value-returning functions
return num1 + num2instead ofresult = num1 + num2; return resultUsing value-returning functions
Example: modularizing with functions
returning strings, Boolean values
returning multiple values
returning
None
9.
mathmodulesqrt,hypot,sin...pi,e, ...
10. Storing functions in modules (Creating your own modules)
Conditionally executing the
mainfunction in a module (if __name__ == '__main__')
11. Turtle: modularizing with functions
e.g.,
square(x, y, width, color)storing functions in a module