Labs and Solutions
Lab 3a - Control Flow with If-Elif-Else
Lab 3a (pdf) covered control flow with if-elif-else statements.
Lab 3b - Control Flow with While
Lab 3b (pdf) covered control flow with while statements.
Lab 4a - Working with Lists
Lab 4a (pdf) covered the use of lists in storing a dynamic number of values.
Example solutions: sorting.py, reportcard.py
Lab 4b - Tuples and Strings
Lab 4b (pdf) covered the use of tuples instead of lists and their similarity with strings.
Example solutions: collision.py, piglatin.py
Lab 6a - Introduction to Objects
Lab 6a (pdf) 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:
- 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.
- 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 bHowever, you can still alias by sayingb = a. Strings are still automatically aliased.
There are no solutions for this lab.
Lab 6b - Working with Objects
Lab 6b (pdf) covered the use of member functions in various objects.
Example solution: genetic.py
Lab 7a - Introduction to Dictionaries
Lab 7a (pdf) 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.
Lab files: namesages.py, websearch1.py, webindexer1.py, htmltext.py, smallsites.txt, mitsites20.txt, mitsites50.txt, localsites.zip
Lab 7b - Compound Dictionaries
Lab 7b (pdf) covered a more advanced use of dictionaries. The bulk of the lab was to improve the web indexer we built in the previous lab.
Lab files: inventory.py, websearch2.py, webindexer2.py
Projects and Sample Programs
Project 1 - Hangman
Project 1 (pdf) was the game of Hangman. The handout guides you through the process. This process is called incremental programming. It allows you to tackle complex problems, like writing a game of Hangman, by tackling small sub-tasks first. In this case, we can tackle the problems of figuring out whether the user has guessed the word, or creating a string of the word with the letters guessed so far. With the sub-tasks taken care of, it's easier to take on the bigger task.
Optional project files: word_list.txt contains many words, hangman_lib.py contains helper functions to get a random word and to print a Hangman image, hangman.py contains example usage of hangman_lib
Notes, Exams and Homeworks
Class 1 Notes
The Class 1 notes (pdf) include the syllabus, some administrativia and an introductory tutorial to Python.
Class 2 Homework
Class 6 Homework
The Class 6 homework (pdf) doubles as notes for classes 4 through 6.
Class 7 Homework
Class 7 homework (pdf) serves as useful practice with lists.
Emails
Miscellaneous