A Gentle Introduction to Programming Using Python

Lecture Notes

Notes and Worksheets

The session 1 notes (PDF) include the syllabus, some administrivia and an introductory tutorial to Python.

Exam 1 (Session 5) covered everything through class 3: variables, types, operators, functions, conditionals and loops. The solutions double as notes for sessions 1 through 3. (PDF)

The session 6 homework (PDF) doubles as notes for classes 4 through 6.

The optional session 7 homework (PDF) serves as useful practice with lists.

The session 8 notes (PDF) cover dictionaries and their usage.

The session 9 worksheet (PDF) reviews common errors and good programming practices.

Handouts

Handout 1 (PDF) reviewed while loops and the basics of for loops.

Handout 2 (PDF) was a heavy review before the midterm, covering functions, lists, for loops and tuples.

Handout 3 (PDF) reviewed objects.

Handout 4 (PDF) reviewed dictionaries and gave guidance on part 1 of the Web indexer lab.

Handout 5 (PDF) was a walkthrough for part 2 of the Web indexer lab, and covered compound dictionaries.

Assignments

This section contains the labs that were done during class, along with example solutions, and a small section ofmiscellaneous items.

Labs and Solutions

DESCRIPTION

FILES

SOLUTIONS

Lab 3 covered control flow with if-elif-else statements.

(PDF)

Lab 4 covered control flow with while statements.

(PDF)

login.py (PY)

nims1.py (PY)

nims2.py (PY)

Lab 5 covered the use of lists in storing a dynamic number of values.

(PDF)

sorting.py (PY)

reportcard.py (PY)

Lab 6 covered the use of tuples instead of lists and their similarity with strings.

(PDF)

collision.py (PY)

piglatin.py (PY)

Lab 7 was a walkthrough tutorial that introduced the idea of objects as opposed to primitive types like ints and floats. By exploring concepts like primitives (e.g. numbers) versus references to objects (e.g. lists), mutability versus immutability, and the effects of scope on objects, we now better understand how to use objects correctly.

Notes

 

1. Some commands will not produce the expected results when performed on the shell. Instead, run the commands from a file. I'm not sure why this is.

2. I was under the impression that Python aliases tuples automatically. It turns out this is not the case. In other words:

a = (1, 2, 3)
b = (1, 2, 3)
print a is b

However, you can still alias by saying b = a. Strings are still automatically aliased.

(PDF)

Lab 8 covered the use of member functions in various objects.

(PDF)

genetic.py (PY)

Lab 9 covered the use and syntax of dictionaries. The bulk of the lab was to explore one common use of dictionaries as indexes, in this case, for searching the Web.

(PDF)

namesages.py (PY)

websearch1.py (PY)

webindexer1.py (PY)

htmltext.py (PY)

smallsites.txt (TXT)

mitsites20.txt (TXT)

mitsites50.txt (TXT)

localsites.zip (ZIP)

namesages_soln.py (PY)

webindexer1_soln.py (PY)

Lab 10 covered a more advanced use of dictionaries. The bulk of the lab was to improve the web indexer we built in the previous lab.

(PDF)

inventory.py (PY)

websearch2.py (PY)

webindexer2.py (PY)

inventory_soln.py (PY)

webindexer2_soln.py (PY)

Miscellaneous

Optional Assignment (PDF): This walks you through the building of a computer from scratch. Starting at the gate level, you'll understand how a computer works.

Operator Cheat Sheet (PDF): This lists some of the various arithmetic and boolean (comparison, equality, and logic) operators we've learned.