Nov 29
Comments posted on work submitted so far. Looks like a good start ...
though in most cases not as far along yet as I would have hoped for.
Let's do a few examples of recursion. (From the previous homework
I think there are still a few questions there - particularly about
making smaller version of lists and strings.)
def palindrome(word):
""" Return True if word is a palindrome
>>> palindrome("a")
True
>>> palindrome("cat")
False
>>> palindrome("dad")
True
"""
print "in palindrome: word = ", word
if len(word) <= 1:
return True
elif word[0] != word[-1]:
return False
else:
return palindrome(word[1:-1])
Big review of everything we've done :
- debugging: ** print everything ** ; doctests
- comments, docstrings, API, "import *" and "from * import *"
- running python : interactive prompt, dir(thing)
- data types : strings, numbers, boolean, lists, dictionaries, files
- operations : + - * ** and or not .
- variables, names, naming conventions
- booleans, conditionals, loops
- functions : arguments, return value, global vs local variables, names
- classes : instances, inheritance, "self"
- workflow ...