Lecture 9: October 29, 2019

Due: Homework 3, due on November 8 at 11:59pm


  1. Tuples
    1. Used to group data
    2. Like lists, but immutable
  2. isinstance(obj,type) function
    1. type is bool, float, int, list, str, tuple
  3. Recursion
    1. n factorial [nfact.py]
  4. Thinking recursively [recfun.py]
    1. First: think of the recursive case (write the problem in terms of something involving a smaller instance of the problem)
    2. Next: think of base case (when to stop)
    3. Example: Find the length of a string
    4. Example: Does the string only have alphabetic characters in it?
    5. Example: Find the maximum element of a list
    6. Example: Construct a string from a list of strings
    7. Example: Reverse a string
  5. Recursion
    1. Palindromes [palindrome.py]
    2. Fibonacci numbers [rfib.py]
    3. Sum of digits [sumdigits.py]
    4. Greatest common divisor [gcd.py]
    5. Nested lists: is an item in a list? [isinlist.py]
    6. Tower of Hanoi [hanoi.py]

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: [email protected]
MISSING TITLE
Version of October 28, 2019 at 11:49PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh