6.189 | January IAP 2008 | Undergraduate

A Gentle Introduction to Programming Using Python


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

Labs and 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.


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.

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.


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.


inventory.py (PY)

websearch2.py (PY)

webindexer2.py (PY)

inventory_soln.py (PY)

webindexer2_soln.py (PY)


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.

Course Info

As Taught In
January IAP 2008
Learning Resource Types
Problem Sets with Solutions
Lecture Notes
Programming Assignments with Examples