T-Th 9:05
or
T-Th 11:15
in Olin 155

CS 1110: Introduction to Computing Using Python

Spring 2014

Lecture Summaries

This page lists a summary of the activities of each week, in reverse chronological order. This is your go-to page for downloading in-class handouts and getting caught back up if you get behind. This page is updated dynamically all semester long, with new material added as we get there.

If you want to see what future lectures in this class will be, you should look at the syllabus page.


Week 17


Week 16

6 May (Tuesday): Valediction

[Presentation]

Summary and some parting thoughts.



Week 15

1 May (Thursday): Grab Bag

[Handout]      [Presentation]
Demos
pyro-9am.py
sparkler-11am.py
draw-11am.py
game2d.py


Today we finish up the extended event-driven examples from the previous lecture, and go on to a grab bag of a last few topics that didn't fit in elsewhere (well, OK, we didn't get to the grab bag). The end is nigh! (The files posted here are the code we developed in class, a bit different from the finished versions posted on the last lecture—complete with typos and sketchy comments! Each of them needs game2d.py to run.)


29 April (Tuesday): Models, Views, Controllers, and Games

[Handout]      [Presentation]
Demos
modules.zip


Today's lecture is focused on A5: we discuss the design of even-driven programs, and demonstrate implementing a couple of fun interactive programs using the A5 skeleton. The zip file contains finished versions of examples similar to the one(s) we developed in lecture.



Week 14

24 April (Thursday): Subclasses and Inheritance

[Handout]      [Presentation]
Demos
resolve.py
override.py
initialize.py


In this lecture we discuss inheritance: relationships between classes that make it easy to share code between classes that have to do similar things.

Reading: Chapter 17; Chapter 18 (especially 18.7)


22 April (Tuesday): Review session

[Presentation]

Review session for prelim 2.



Week 13

17 April (Thursday): More Algorithms with Loop Invariants

[Handout]      [Presentation]
Demos
linear_search.py
binary_search.py
selection_sort.py


Continuation of sequence algorithms using an invariant-based approach. The presentation slides posted here contain the solutions that we did in class.

Reading: Handout on loop invariants


15 April (Tuesday): Invariants, quicksort, partition

[Handout]      [Presentation]

Today we (in 9:05 practiced using invariants to debug, and then) develop some elegant algorithms on sequences (strings, lists, and tuples) using an invariant-based approach. Full solutions are in the presentation slides posted here.

Reading: Handout on loop invariants



Week 12

10 April (Thursday): Loop Invariants

[Handout]      [Presentation]
Demos
adj_pairs_many_many_variants.skeleton.py
adj_pairs_many_many_variants.py


This lecture advances our understanding of the technique of using loop invariants to reason about the correctness of code that uses loops. The demo code contains functions that all do exactly the same thing, but are based on different invariants or implementations of those variants, for both while-loops and for-loops. One version is a skeleton for you to practice coding with: you're given the invariant to work with. The other version has full solutions, and in certain cases gives two solutions for the same invariant.

Reading: Writeup and worked exercises on loop invariants


8 April (Tuesday): While Loops

[Handout]      [Presentation]
Demos
cuberoot.py
lec19.py


In this lecture we introduce while loops and begin talking about iteration and how to use it effectively. We develop several simple iterative functions using for and while loops.

Reading: Writeup and worked examples on loop invariants (plus section 7.3 of the text)



Week 11


Week 10

27 March (Thursday): Monte Carlo Card Tricks

[Handout]      [Presentation]
Demos
lec18-code.zip


In this lecture we do “coding theater,” implementing a program that uses a simple Monte Carlo method to find out the probabilities of various hands in various versions of poker. Along the way we see a few more odds and ends of the Python language, as well as some implementation patterns that you can adapt to your own code later. The Zip file of code contains a finished version of the program, as well as the starting state and the states at the end of each of the lectures, so you can see what you remember us doing in class.

Reading: Chapter 18


25 March (Tuesday): Using Classes Effectively

[Handout]      [Presentation]
Demos
time.py
rectangle.py
card.py
hand.py


Today we look at how to use the mechanisms of classes and objects that we saw in the previous lecture to implement well-behaved classes.

Reading: Chapters 15, 16



Week 9

20 March (Thursday): Back to recursion

[Handout]      [Presentation]
Demos
animate.py
palindromes.py
palindromestest.py
was_influenced_by and how to try it out


We cover some more examples of recursion, with some of our discussion in the context of A3. The animate.py script can be used by you to visualize "animated" versions of trials once your code is working.


18 March (Tuesday): Defining and Using Classes

[Handout]      [Presentation]
Demos
trivial.py
example2.py
worker.py


Today we start the next major segment of the course. We finally learn what all of this "object-oriented" stuff is about. We have seen objects, but they are a bit mysterious and always required some special module in the background. Today we learn about how classes actually work, and how to define new ones.

Reading: Chapters 15, 16



Week 8

13 March (Thursday): More on Recursion

[Handout]      [Presentation]
Demos
lec14.py
lec14test.py


We consider what happens on the call stack when a recursive function is executed, and we look at different ways that we can break up the input to a recursive method.

Reading: (none)


11 March (Tuesday): Review session for Prelim 1

[Presentation]

We will use lecture to review the topics that will be covered on the prelim, following roughly the plan of the previous year's prelim review.



Week 7

6 March (Thursday): Recursion

[Handout]      [Presentation]
Demos
embedding.py
embeddingtest.py
string_recursion.py
string_recursion_test.py
math_recursion.py
math_recursion_test.py


Today we introduce recursion. Recursion is one of the fundamental principles of computer science, and is used for a lot of advanced algorithms. We see an application to understanding sentential structure in natural language.

Reading: Section 5.8-5.10, 6.6


4 March (Tuesday): Iteration over sequences

[Handout]      [Presentation]
Demos
spellcheck.py
scowl_utf-8.txt
const.txt


Today we introduce two ways to do something for each item of a list (or other sequence). The built-in function "map" will call a function once for each item in a list. Or you can use the "for" statement to execute a block of one or more statements for each item in a list.

Reading: Section 10.3, 10.7



Week 6

27 February (Thursday): More with Sequences

[Handout]      [Presentation]

Today we continue looking at what we can do with lists. We learn how to make multidimensional lists by nesting lists inside other lists. We look at a few examples of useful programs that can be written succinctly with lists and strings. We didn't get to the two basic ways of processing each item in a list: the map function and the for statement. We looked at the wordcount demo (code and text data posted back at lecture 9).

Reading: Sections 10.1-10.2, 10.4-10.6, and 10.8-10.13


25 February (Tuesday): Lists and Sequences

[Handout]      [Presentation]
Demos
wordcount.py
jabber.txt
sestina.txt
road-not-taken.txt
README.html


Today we cover the general topic of sequences, and more specifically lists. Sequences are a category that includes both strings and lists; sequences can be sliced up in the way that strings can. Lists, however, are different in that they are mutable and can contain objects of any type. We will see why this is important.

Reading: Sections 10.1-10.2, 10.4-10.6, and 10.8-10.13



Week 5

20 February (Thursday): Conditionals

[Handout]      [Presentation]
Demos
fdemo.py
testfdemo.py
clickerq.py


If-statements, and conditional expressions, using a post-Valentine's-Day demo.

Reading: 5.4-5.7



Week 4

13 February (Thursday): More on Function Calls and Frames

[Handout]      [Presentation]
Demos
lec07.py
lec07_pythontutorized.py
Additional
In-class exercise


We practice more with function calls and call frames, trying to keep straight what names are available, where these names exist, and what things we can affect inside and outside a frame.

The version of the presentation slides posted here contain pseudo-animated solutions to all the exercises we did in class. You can also visualize the solutions in the Online Python Tutor using the simplified snippets included in the lec07_pythontutorized.py file. (Handling imports of external modules is a little tricky in the Python Tutor.)

Reading: Sections 3.9-3.10


11 February (Tuesday): Function Calls; Call Frames

[Handout]      [Presentation]
Demos
add.py
swap.py
swap_x.py
f-and-g.py
energy.py


We look more closely at what goes on when you call a function. We introduce call frames, the paper-and-pencil model for function calls, and use them to show what happens with parameters, arguments, and local and global variables.

Reading: Sections 3.7-3.14



Week 3

6 February (Thursday): Objects

[Handout]      [Presentation]
Demos
tuple3d.py


Objects are a more general data type. To understand them, we introduce the folder metaphor which we will use throughout this course.

Reading: Sections 3.5-3.13 and 6.1-6.4


4 February (Tuesday): Writing Functions; Specifications; Testing

[Handout]      [Presentation]
Demos
string.py
gym.py
testgym.py
cornelltest.py


Today we see how to use pre-written functions and how to define our own functions, stressing the importance of good specifications and testing. We introduce the unit-test method of organizing test cases.

Reading: Sections 3.1-3.6; 4.9 (docstring); 14.9 (writing modules)



Week 2

30 January (Thursday): More on Strings; Files

[Handout]      [Presentation]
Demos
string_puzzle_soln.py
string_puzzle_df_soln.py


We first practice doing extraction of data from strings. As we perform longer sequences of operations, we move away from working at the Python prompt to using Komodo Edit to write Python programs, running them using the command shell.
The python demos include multiple solutions to the string-processing puzzles, the second of which we didn't get to in lecture but can be seen on the note-taking handout.

Reading: 8.1-8.2; 8.4; 8.8-8.9


28 January (Tuesday): Variables and Assignment; Strings

[Handout]      [Presentation]

We cover a bit more course mechanics, finish up types and expressions, then introduce the notion of a variable and cover exactly how an assignment statement works. Finally we start talking about strings. We will use the iClickers for the first time today, but will not count the responses for participation grade until next week.

Reading: Sections 2.2-2.9



Week 1

23 January (Thursday): Types and Expressions

[Handout]      [Presentation]
Additional
First Day Announcements
Learning Styles


We give an overview of the course and its expectations. We show you how to get started with Python. Finally, we talk about types and expressions, which is the bare minimum that you need to do something "useful" in Python.

Reading: Chapter 1; Section 2.1



Course Material Authors: D. Gries, L. Lee, S. Marschner, & W. White (over the years)