Topics: Exceptions, assertions Introduced to the try/except code blocks, with some examples. Also introduced to assertions, as a way to program defensively. I sort of forgot about assertions so this is good review. I will look to use them in my future code. They are good for enforcing invariants …
State machines are a simple, abstract model of step-by-step processes. One of the most important uses of induction in computer science involves proving one or more desirable properties continues to hold at every step in a process. A property that is preserved through a series of operations or steps is …
Topics: More Functions as Objects, Keyword Arguments, Default Arguments, Debugging: glass box/black box testing, examples List comprehensions are review for me. Default parameters are also review. Functions can return another function. Why bother returning functions? Code can be rewritten without returning function objects Good software design Embracing ideas of …
Topics: Aliasing and cloning Going over some operations on lists, including .clear(), .pop(), del() and .remove(). Iterating over a list as you are mutating the list can lead to unpredictable behavior. Takeaway here is to be careful when mutating a list while iterating over it. Consider using a copy. = sign …
Abstraction Module In this module we look another techniques for improving the structure of code. Most of the problems in this module involve refactoring existing programs -- so there's relatively little new coding to do. But that doesn't mean you won't be designing programs! One of the things that separates good …
Problem 1: I was able to get the base cases, but couldn’t make the jump to the induction step. I ended up looking at the solution. Problem 2: This was a little complicated, I didn’t even know where to start. So I looked up solution as well. Problem …
I was able to complete this problem set in just under an hour. It was good practice. Will show my code then the result of running the unit tests. My solution: import random import string # ----------------------------------- # HELPER CODE # ----------------------------------- WORDLIST_FILENAME = "words.txt" VOWELS = 'aeiou' def load_words(): """ returns: list, a list of valid …
In this module we look at a new technique for improving the structure of code. Most of the problems in this module involve refactoring existing programs -- so there's relatively little new coding to do. But that doesn't mean you won't be designing programs! One of the things that separates good …
Module Overview Two One-Of Types In this module we will learn to design functions consuming two arguments that have one-of types. In order to do this, we will develop a new model of our code, the cross product of the types comment table. The cross product of the types comment …
Induction is a powerful method for showing a property is true for all non-negative integers. Induction plays a central role in discrete mathematics and computer science. In fact, its use is a defining characteristic of discrete—as opposed to continuous—mathematics. This chapter introduces two versions of induction, Ordinary and …