A Gentle Introduction to Programming Using Python

Lectures

LEC #

TOPICS

HANDOUTS AND EXAMPLES

1

Introduction

Getting started (PDF)

raw_input_example.py (PY)

2

Conditionals, loops

How to comment code properly (PDF)

height_example.py (PY)

conditional_examples.py (PY)

loop_examples.py (PY)

3

Defining functions

lecture3.py (PY)

functions.py (PY)

check_for_vowels.py (PY)

4

Strings, lists, list comprehensions

string_examples.py (PY)

list_examples.py (PY)

comprehension_examples.py (PY)

Additional Material

Two examples of a rock-paper-scissors program:

rps_example1.py (PY)

rps_example2.py (PY)

How to use while-else loops (suggestion: don't use them at all, but if you do be aware they work differently than you might think):

while_else.py (PY)

Optional lecture

Recursion

Recursion notes (PDF)

Recursion examples (PY)

Optional problems (PDF)

Solutions to optional problems (PY)

5

Tuples, dictionaries, common Python mistakes

tuple_examples.py (PY)

Remember that the keys of a dictionary must be immutable objects, but thevalues of a dictionary can be either immutable or mutable objects.

Common Python mistakes and misconceptions (PDF)

6

Classes

point.py (PY)

7

More about classes

wheel.py (PY)

8

Inheritance

inheritance_examples.py (PY)

Assignments

If you are working on your own machine, you will probably need to install Python. We will be using the standard Python software, available here. You should download and install version 2.6.x, not 2.7.x or 3.x. All MIT Course 6 classes currently use a version of Python 2.6.

ASSN #

ASSIGNMENTS

SUPPORTING FILES

Homework 1

Handout (PDF)

Written exercises (PDF)

Code template (PY)

Homework 2

Handout (PDF)

Written exercises (PDF)

Code template (PY)

nims.py (PY)

strings_and_lists.py (PY)

Project 1: Hangman

Handout (PDF)

hangman_template.py (PY)

words.txt (TXT)

Optional extension:

hangman_lib.py (PY)

hangman_lib_demo.py (PY)

Homework 3

Handout (PDF)

Written exercises (PDF)

Code template (PY)

Homework 4

Handout (PDF)

Written exercises (PDF)

Graphics module documentation (PDF)

graphics.py (PY) — be sure to save this in the same directory where your code is saved!

wheel.py (PY)

rgb.txt (TXT)

The graphics.py package and documentation are courtesy of John Zelle, and are used with permission.

Project 2: Conway's game of life

Handout (PDF)

game_of_life_template.py (PY) — download and save as game_of_life.py; be sure to save in the same directory as graphics.py

Final project: Tetris

Handout (PDF)

tetris_template.py (PY) — Download and save it in the same directory as graphics.py. Please edit this file, and place your code in the sections that say "YOUR CODE HERE".

Exams

The purpose of the test is to give you an idea of the kind of comfort with programming that we'd like you to get to very quickly in 6.01. If you do fine on this test, you should have no difficulty with the programming aspects of 6.01 on start-up. See how far you can get with this in 1–2 hours.

Sample Python exam (PDF)

Solutions (PY) (Courtesy of Kat Kononov and Sarina Canelake. Used with permission.)