Outline for October 18, 2022
Reading:
§4.9
Assignment:
Homework 2, due October 20, 2022
Lists as parameters: can change list elements in function and they are changed in caller [
args2.py
]
More on parameters: named arguments and variable number of arguments [
args3.py
]
isinstance(obj,type)
function
type
is
bool
,
float
,
int
,
list
,
str
,
tuple
Recursion
n
factorial [
nfact.py
]
Thinking recursively [
recfun.py
]
First: think of the recursive case (write the problem in terms of something involving a smaller instance of the problem)
Next: think of base case (when to stop)
Example: Find the length of a string
Example: Does the string only have alphabetic characters in it?
Example: Find the maximum element of a list
Example: Construct a string from a list of strings
Example: Reverse a string
Recursion
Palindromes [
palindrome.py
]
Fibonacci numbers [
rfib.py
]
Tower of Hanoi [
hanoi.py
]
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email:
mabishop@ucdavis.edu
MHI 289I, Programming in Health Informatics
Version of October 18, 2022 at 7:28PM
You can also obtain a PDF version of this.