Lecture 9: October 29, 2019
Due
: Homework 3, due on November 8 at 11:59pm
Tuples
Used to group data
Like lists, but immutable
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
]
Sum of digits [
sumdigits.py
]
Greatest common divisor [
gcd.py
]
Nested lists: is an item in a list? [
isinlist.py
]
Tower of Hanoi [
hanoi.py
]
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email:
mabishop@ucdavis.edu
MISSING TITLE
Version of October 28, 2019 at 11:49PM
You can also obtain a PDF version of this.