| 1 |
Tue, 1 Sep |
Introduction to Programming; Objects slidesfinger ex.readings- Guttag ch. 1
- Getting Started. What computation is, algorithms as recipes, and the difference between syntax, static semantics and semantics. Short; read it all, and try the finger exercise at the end.
- Guttag §2.1 (opening)
- The Basic Elements of Python: a program is a sequence of statements, the shell, and what print does.
- Guttag §2.1.1
- Objects, Expressions, and Numerical Types: every value is an object with a type; int, float, bool and None; the type() function. Read up to Figure 2.1 — the operators are next lecture.
- Guttag §2.1.3
- Python IDE's. Skim only: the book uses Anaconda, we use Thonny, but the editor/shell/debugger picture is the same.
|
— |
— |
| 2 |
Thu, 3 Sep |
Expressions, Variables slidesfinger ex.readings- Guttag §2.1.1 (from Figure 2.1)
- Operators on int and float, precedence and parentheses, == versus =, and the and / or / not operators. Try each example in the shell.
- Guttag §2.1.2
- Variables and Assignment: a variable is a name bound to an object (Figure 2.2), rebinding, choosing readable names, reserved words, comments, and multiple assignment (x, y = y, x). The core of this lecture.
|
OS navigation, command line, Thonny |
— |
| 3 |
Tue, 8 Sep |
Strings, Input/Output slidesfinger ex.readings- Guttag §2.3
- Strings and Input: string literals, + and * on strings, len, indexing and slicing, and the input function. Read before class.
- Guttag §2.3.1–2.3.2
- Input in detail, and the digression on character encoding. The encoding part is background; skim it.
- Guttag §5.5 (string methods)
- Strings, Tuples, Ranges, and Lists — only the string methods table near the end (find, split, strip, …). We use these from now on; ignore the tuple/list parts until lecture 11.
|
— |
|
| 4 |
Thu, 10 Sep |
Boolean Expressions slidesfinger ex.readings- Guttag §2.1.1 (end)
- The bool type and the primitive operators and, or, not — the last half page of the section. Re-read it.
- Guttag §2.2 (first half)
- Branching Programs, up to the first flowchart: how a boolean expression drives an if statement. The rest of §2.2 is next lecture.
|
Expressions, Variables |
— |
| 5 |
Tue, 15 Sep |
Conditions slidesfinger ex.readings- Guttag §2.2
- Branching Programs in full: if / elif / else, nested conditionals, and why indentation is the block structure. Do the finger exercises.
|
— |
|
| 6 |
Thu, 17 Sep |
Problem Set 1 |
I/O, Boolean expressions |
|
| 7 |
Tue, 22 Sep |
Iteration slidesfinger ex.readings- Guttag §2.4
- Iteration: the while loop, the loop flowchart, and hand-simulating a loop (Figure 2.6). Read before class.
- Guttag §3.1
- Exhaustive Enumeration: the first useful thing a loop can do — guess-and-check. Short.
- Guttag §3.2
- For Loops and range. We treat for as the everyday loop and while as the special case; the book does the reverse.
|
— |
— |
| 8 |
Thu, 24 Sep |
Problem Set 2 |
Conditions |
|
| 9 |
Tue, 29 Sep |
Code Abstraction, Functions slidesfinger ex.readings- Guttag §4.1–4.1.2
- Functions and Scoping: def, parameters and arguments, return, keyword arguments and default values. Stop before §4.1.3 — scoping is next lecture.
- Guttag §4.2
- Specifications: what a docstring promises and why 'decomposition and abstraction' are the point of functions.
|
— |
quiz 2 |
| 10 |
Thu, 1 Oct |
Environment Diagrams slidesfinger ex.readings- Guttag §4.1.3
- Scoping: the three rules for name lookup and the stack-frame pictures (Figures 4.2 and 4.3). These are the environment diagrams we draw in class — read it twice.
- Guttag §4.4
- Global Variables. Why the book calls them 'a good way to make programs hard to understand'. Short, optional.
|
Iteration lab 05 |
— |
| 11 |
Tue, 6 Oct |
Tuples, Lists slidesfinger ex.readings- Guttag §5.1–5.1.1
- Tuples, and sequences with multiple assignment. Immutable first, so mutability stands out later.
- Guttag §5.2
- Ranges. Half a page; it explains what range actually returns.
- Guttag §5.3 (up to Figure 5.3)
- Lists and Mutability: literals, indexing, append and the list methods table (Figure 5.4). Stop at the aliasing discussion — that is next lecture.
|
— |
A1 dueA2 released |
| 12 |
Thu, 8 Oct |
Aliasing, Cloning slidesfinger ex.readings- Guttag §5.3 (from Figure 5.3)
- Aliasing: two names for one list, and why mutation through one name shows up through the other. The most important idea in the chapter.
- Guttag §5.3.1
- Cloning: L[:], list(L), and when a copy is not deep enough.
- Guttag §5.5
- Strings, Tuples, Ranges, and Lists compared (Figures 5.6–5.7): which are mutable, which are not.
|
Functions lab 06 |
quiz 3 |
| 13 |
Tue, 13 Oct |
Comprehensions, 2-D Lists slidesfinger ex.readings- Guttag §5.3.2
- List Comprehension. One page; then rewrite last week's loops as comprehensions.
- Guttag §5.4
- Functions as Objects: map and passing functions around. Optional — a preview of what comprehensions generalise.
- Python docs Data Structures §5.1.4
- Nested list comprehensions and the matrix-transpose example: the tutorial's treatment of lists of lists, which the book does not cover.
|
— |
— |
| 14 |
Thu, 15 Oct |
Problem Set 3 slides |
Lists lab 07 |
— |
| — |
Tue, 20 Oct |
Midterm Examination |
— |
exam paperA2 dueA3 released |
| — |
Thu, 22 Oct |
Fall Break — no class |
— |
— |
| 15 |
Tue, 27 Oct |
Search, Approximation slidesfinger ex.readings- Guttag §3.1
- Exhaustive Enumeration, re-read now that you can write loops fluently.
- Guttag §3.3
- Approximate Solutions and Bisection Search: 'close enough' as a stopping condition, then halving the interval.
- Guttag §3.4
- A Few Words About Using Floats: why 0.1 is not 0.1, and what it means for == on floats.
- Guttag §10.1
- Search Algorithms: linear search, then binary search on sorted lists. Optional now; we return to it with Big-O.
|
— |
— |
| 16 |
Thu, 29 Oct |
Assertions, Exceptions slidesreadings- Guttag §7.1
- Handling Exceptions: try / except, the common exception types, and catching only what you mean to.
- Guttag §7.2
- Exceptions as a Control Flow Mechanism: raise, and returning errors versus raising them.
- Guttag §7.3
- Assertions: assert as a check on your own assumptions, not on user input. Half a page.
|
Advanced Lists lab |
— |
| 17 |
Tue, 3 Nov |
Dictionaries slidesfinger ex.readings- Guttag §5.6
- Dictionaries: keys and values, the operations table (Figure 5.10), iteration order, and what can be a key. Read before class.
|
— |
quiz 4 |
| 18 |
Thu, 5 Nov |
Counting Steps, Big-O slidesfinger ex.readings- Guttag §9.1
- Thinking About Computational Complexity: counting steps, best/worst/average case. Read before class.
- Guttag §9.2
- Asymptotic Notation: what Big-O actually says and what it throws away.
- Guttag §9.3
- Some Important Complexity Classes, constant through exponential, with an example of each. §9.3.7 has the comparison plots.
|
Search, Approximation, Exceptions lab |
A3 dueA4 released |
| 19 |
Tue, 10 Nov |
Sorting slidesfinger ex.readings- Guttag §10.2–10.2.1
- Sorting Algorithms and Merge Sort: the divide-and-conquer argument and why it is n log n.
- Guttag §10.2.2–10.2.3
- Sorting with a key function, and Python's built-in sort and sorted. This is what you will actually call.
- Guttag §10.1.2
- Binary Search and Exploiting Assumptions: why sorting first can pay for itself. Optional.
|
— |
— |
| 20 |
Thu, 12 Nov |
Codes & Codebreakers slidesfinger ex.readings- Guttag §5.6 (Figure 5.9)
- Translating text (badly): a substitution cipher is a dictionary lookup per word. The whole lecture is this figure grown up.
- Guttag §5.5
- String methods you need for ciphers: split, join, lower, and the character-by-character loop. Re-read.
- Guttag §2.3.2
- Character encoding, ord and chr. Needed for shift ciphers. Short.
|
Dictionaries, Big-O lab |
— |
| 21 |
Tue, 17 Nov |
Recursion and the Call Stack slidesfinger ex.readings- Guttag §4.3
- Recursion: the base case, the recursive case, and factorial done both ways. Read before class.
- Guttag §4.1.3 (Figure 4.3)
- Stack frames, re-read: each recursive call is one more frame. Draw the frames for fact(3) by hand.
|
— |
quiz 5 |
| 22 |
Thu, 19 Nov |
Thinking Recursively slidesfinger ex.readings- Guttag §4.3.1
- Fibonacci Numbers: two base cases, and the problem of recomputing the same values.
- Guttag §4.3.2
- Palindromes: recursion on strings, and the 'divide, conquer, combine' template we reuse.
- Guttag §13.1
- Fibonacci Sequences, Revisited: memoization fixes the recomputation. Optional; we return to it in lecture 26.
|
Sorting, Ciphers lab |
— |
| 23 |
Tue, 24 Nov |
Randomness and Simulation slidesfinger ex.readings- Guttag §15.1–15.2
- Stochastic Programs and Calculating Simple Probabilities: random.random, random.choice, and what 'the same program gives different answers' means. Read before class.
- Guttag §14.1–14.2
- Random Walks and the Drunkard's Walk: the simulation we build in class, minus the classes.
- Guttag §16.4
- Finding π by throwing darts. Short, and the best two-page argument for why simulation works.
|
— |
— |
| 24 |
Thu, 26 Nov |
Plotting slidesfinger ex.readings- Guttag §11.1
- Plotting Using PyLab: plot, title, labels, legends, figure, and saving to a file. The book uses pylab; matplotlib.pyplot is the same functions under the name we use.
- Guttag §14.2 (plots)
- The drunkard's-walk plots: a worked example of turning simulation output into a figure. Optional.
|
Recursion lab |
A4 due |
| 25 |
Tue, 1 Dec |
Testing, Debugging; Type Annotations slidesfinger ex.readings- Guttag §6.1
- Testing: black-box versus glass-box tests, boundary cases, and how to choose test inputs.
- Guttag §6.2
- Debugging: treat a bug as an experiment (§6.2.2), and what to do when the going gets tough (§6.2.3).
- Python docs typing — Support for type hints
- Type annotations are not in this edition of the book. Read the first screen of the typing docs; we use annotations as documentation only.
|
— |
quiz 6 |
| 26 |
Thu, 3 Dec |
Making Python Faster slidesfinger ex.readings- Guttag §13.1
- Fibonacci Sequences, Revisited: memoization — remember answers instead of recomputing them.
- Guttag §16.3
- Using Table Lookup to Improve Performance: the same idea applied to a simulation, with timings.
- Guttag §10.3
- Hash Tables: why dictionary lookup is constant time, and therefore why 'use a dict' is so often the fix.
- Guttag §9.3.7
- Comparisons of Complexity Classes: pick the better algorithm before you tune the code. Re-read.
|
Simulation, Plotting lab |
— |
| 27 |
Tue, 8 Dec |
Course Review & Exam Preparation slidesreadings- Guttag Appendix: Python 3.5 Quick Reference
- The whole language we used, on four pages. Read it and mark anything you cannot explain — that is your revision list.
- Guttag ch. 1–7, 9–10
- Everything examinable is in these chapters. Re-do the finger exercises rather than re-reading the prose.
|
— |
— |
| — |
Thu, 10 Dec |
Final Examination |
— |
exam paper |