T-Th 9:05 or 11:15
in Kimball B11

CS 1110: Introduction to Computing Using Python

Spring 2013

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. You may also find the lecture handouts from last semester useful.


Week 15


Week 14

2 May (Thursday): Review session



The final is comprehensive, but during today's review session, we focused on an extended exercise on objects, subclasses, and reference. The posted slides also contain some solved exercises with try-clauses and a loop question. See the Exams page for the slides.



Lab 14: Office hours/check off lab 13



No new lab exercise; you can come to check off lab 13 or ask questions of the staff about the next assignment, or not come at all.


30 April (Tuesday): Grab Bag

[Handout]     

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. The end is nigh!



Week 13

25 April (Thursday): Event-driven Programming

[Handout]      [Presentation]
Demos
draw.zip
pyro.zip
modules.zip


Today's lecture is focused on A7: we discuss the design of even-driven GUI programs, and demonstrate implementing a couple of fun interactive programs using the A7 skeleton. The accompanying code here is the finished versions of the programs I worked on in lecture; I'll show more of the development toward the finished states on Tuesday.



Lab 13: Subclasses; exceptions

[Instructions]

This lab gives you some practice with writing a subclass and using exceptions to your advantage.


23 April (Tuesday): 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)



Week 12

18 April (Thursday): Exceptions and Try-statements

[Handout]      [Presentation]
Demos
recip.py


What happens when something goes wrong (in Python)? Python runtime errors are objects (of course!) called exceptions. We'll talk about how to handle exceptions gracefully and usefully. The fact that exceptions are part of a class hierarchy will lead us to our next topic, sub-classes and inheritance.

Reading: 14.5, A.2.3



Lab 12: Office hours Tuesday/nobody there Wed



The Tuesday labs will be office hours; the Wednesday labs are canceled completely (no staff will be there).


16 April (Tuesday): Prof office hours (exam day)



Held in Thurston 102.



Week 11

11 April (Thursday): Review session

[Handout]      [Presentation]

Review session for prelim 2.



Lab 11: Office hours/check off lab 10



No new lab exercise; you can come to check off lab 10 or ask questions of the staff about the next assignment or the loop-invariants handout, or not come at all.


9 April (Tuesday): More Algorithms with Loop Invariants

[Handout]      [Presentation]

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



Week 10

4 April (Thursday): Sequence algorithms

[Handout]      [Presentation]
Demos
algorithms.py
cunittest2.py


Today we talk about how to create complex algorithms on sequences (strings, lists, and tuples) using an invariant-based approach. Full solutions are in the code.

Reading: Handout on loop invariants



Lab 10: Loop Exercises

[Instructions]

The purpose of this lab is to give you some practice with loop assertions (preconditions, postconditions, and invariants) and with while loops that process a range of integers. It is a mixture of coding exercises and answers to be written on paper.


2 April (Tuesday): Loop Invariants

[Handout]      [Presentation]

This lecture introduces the technique of using loop invariants to reason about the correctness of code that uses loops.



Week 9

28 March (Thursday): While Loops

[Handout]      [Presentation]
Demos
iterative.py
testlab.py
cunittest2.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: Chapter 7



Lab 9: Office hours/check off lab 8



No new lab exercise; you can come to check off lab 8 or ask questions of the staff about A4, or not come at all.


26 March (Tuesday): Monte Carlo Card Tricks

[Handout]      [Presentation]
Demos
lec17-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



Week 8

14 March (Thursday): 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



Lab 8: Classes: Blackjack

[Instructions]

You'll practice writing a class definition, in the context of a program that allows you to play blackjack. The module skeleton also contains a while-loop, which you may wish to gaze upon now and which we'll learn about later.


12 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 7

7 March (Thursday): Prof. office hours for Prelim 1



 



Lab 7: Office hours/work on lab 6



No new lab exercise; you can come to work on lab 6 or ask questions of the staff during your prelim preparation, or not come at all.


5 March (Tuesday): Review session for Prelim 1

[Presentation]

 



Week 6

28 February (Thursday): More on Recursion

[Handout]      [Presentation]
Demos
lec12.py
lec12test.py
cunittest2.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. Note: presentation version now contains both versions of the “what if no base case” scenario.

Reading: (none)



Lab 6: Recursion Exercises

[Instructions]

This lab gives you practice writing recursive functions. All of the functions in this lab are either be recursive functions on sequences, or recursive functions on integers, just as we saw in class. This is a challenging lab, but you have until the week after the prelim to finish it.


26 February (Tuesday): Recursion

[Handout]      [Presentation]
Demos
embedding.py
test_embedding.py
math_recursion.py
string_recursion.py
test_math_recursion.py
test_string_recursion.py
cunittest2.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 saw an application to understanding sentential structure in natural language.

Reading: Section 5.8-5.10, 6.6



Week 5

21 February (Thursday): More with Sequences

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


Today we continue looking at what we can do with lists. We learn two ways to process the elements of a list: the map function and the for statement. We look at a few examples of useful programs that can be written succinctly with these tools. We didn't get to how to make multidimensional lists by nesting lists inside other lists.

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



Lab 5: Lists; Conditionals: Cards and Poker Hands

[Instructions]

We practice with lists and conditionals by considering lists of Card objects, enabling us to draw poker hands.


19 February (Tuesday): Lists and Sequences

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


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 4

14 February (Thursday): The Call Stacks; Conditionals

[Presentation]
Demos
flower.py


We continue with the concept of call frames, putting it in the context of the “call stack”, which is the ordered collection of frames for all currently executing functions. We also show how this is relevant to error detection in a program.

We then switch to the topic of if-statements, and conditional expressions, using a special Valentine's Day demo.

No new lecture handout; refer to last lecture.

Reading: Sections 3.1-3.10 and 5.1-5.7



Lab 4: Catch-up for labs 2 and 3



Students who have already received a grade for labs 2 and 3 need not attend.


12 February (Tuesday): More on Function Calls and Frames

[Handout]      [Presentation]
Demos
lec07.py
point.py
Additional
pdf version of slides (better to see the pptx, because of the animations)
In-class exercise


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

Note that presentation slides linked to above show an animated version what happened on the board, more or less (if you can't view powerpoint slides, a static pdf is linked to on the right), and you can run our various attempts to change the speed of light using the lec07.py file (in Python, or perhaps even better, using the Online Python Tutor), and even play around with other possibilities.

Reading: Sections 3.9-3.10



Week 3

7 February (Thursday): 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



Lab 3: Objects, Functions, and Testing

[Instructions]

We practice writing and testing a function that acts on objects. This lab is (hopefully) shorter than usual to allow students to catch up from lab 2.


5 February (Tuesday): Objects

[Handout]      [Presentation]
Demos
point.py
jabber.txt


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



Week 2

31 January (Thursday): Writing Functions; Specifications; Testing

[Handout]      [Presentation]
Demos
gym.py
testgym.py
cunittest.py


Today we show 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



Lab 2: Strings, Functions, and Modules: Scraping Exam Info from the Web

[Instructions]

The purpose of this lab is to get you comfortable with using Python functions and modules. Python has a lot of built-in modules, which collectively are called the Python library. You'll also practice more with string processing.


29 January (Tuesday): More on Strings; Modules; Functions

[Handout]      [Presentation]
Demos
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 command prompt to using Komodo Edit to write and run Python programs; in doing so, we introduce one debugging technique: judicious use of print statements. We can use functions in our code, some of which are accessed by importing modules.

Reading: (Note that these are all short!) Sections 2.6, python files (referred to there as "scripts"); 2.9, comments; 4.9, docstring; 3.3, for import and dot notation; 8.1, 8.2, 8.4, 8.5, 8.8, about string operations, including the dot notation. Don't worry about the "method" terminology (yet); 3.1-3.6, about functions



Week 1

24 January (Thursday): 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 talk about strings, how to extract parts of them, and a few of the many handy string processing features in Python. 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



Lab 1: Evaluating Expressions

[Instructions]

The purpose of this lab is two-fold: (a) to get you started with Python immediately; (b) to give you hands-on experience with expressions, the topic of the first lecture.


22 January (Tuesday): 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