Think Python
by Allen Downey, 2012
Olin College, MA
This textbook is open-source; we have reorganized and edited it to match our course syllabus.


Python 3


Introduction to solving computational problems, including the fundamentals of computer programming. Topics include imperative programming constructs (variables, loops, conditionals, functions, recursion), basic object-oriented constructs (classes, objects), and some fundamental algorithms and data structures (dictionaries, arrays, linked lists, basic sorting). Student learn these concepts through studying the Python programming language.

At the end of the course, you will be expected to be able to:

  • Read, understand and execute a computer program written in Python.
  • Read a set of requirements for a computer program in English, and write a short Python program (100 lines or less) that corresponds to them.
  • Test a Python program and identify and fix programming errors.
  • Identify some errors in a Python program without testing it.
  • Without using a computer, write a very short Python code fragment (10 lines or less) that correctly implements a set of requirements.
  • Understand and apply variables, loops, strings, lists, conditionals, and functions.
  • Write programs to perform mathematical calculations.
  • Understand the concept of a module.
  • Write a Python program that is separated into at least two modules.
  • Understand the concepts of class and object, and distinguish between them.
  • Write a Python program including objects of at least one student-designed class.
  • Write and understand appropriate comments in a Python program.
  • Understand the concept of an algorithm and compare the efficiency of different algorithms for a simple task.


It is the policy of Hendrix College to accommodate students with disabilities, pursuant to federal and state law. Students should contact Julie Brown in the Office of Academic Success (505.2954; brownj@hendrix.edu) to begin the accommodation process. Any student seeking accommodation in relation to a recognized disability should inform the instructor at the beginning of the course.

Academic Integrity

All Hendrix students must abide by the College’s Academic Integrity Policy as well as the College’s Computer Policy, both of which are outlined in the Student Handbook.

For specific ways the Academic Integrity policy applies in this course, please refer to the Computer Science Academic Integrity Policy.

The short version is that academic integrity violations such as copying code from another student or the Internet are easy to detect and will be taken very seriously.

If you have any questions about how the Academic Integrity policy applies in a particular situation, please contact me.


Please do not bring laptops to lecture. This may seem strange in a computer science class. But lab is the place where you will get plenty of experience working on the computer; lecture is a time for thinking and learning without the distraction of a computer.

Exceptions may be made on a case-by-case basis if you can prove to me that you really do benefit from using your laptop to take notes.


PDF syllabus

We will be covering most of the material in the textbook, approximately one new chapter each week. You should view your textbook as another perspective on the material presented in class and covered in the labs. We will also be using additional supplemental material such as relevant web pages and background material for the lab assignments. Readings will be assigned before material will be covered in class. You are expected to review the material and come to class prepared.

  • Wed, Jan 17: Introduction
  • Fri, Jan 19: Algorithms, Collatz conjecture (Chapter 1)
  • Mon, Jan 22: Intro to Python [ intro.txt ] (Chapter 2)
  • Weds, Jan 24: Volume of a box [ VariablesIO.py Box.py ] (Chapter 3)
  • Fri, Jan 26: Logic puzzles
  • Mon, Jan 29: Booleans and conditionals [ Conditionals.py ] (Chapter 4)
  • Wed, Jan 31: Binary
  • Fri, Feb 2: Information encoding
  • Mon, Feb 5: Information encoding II
  • Wed, Feb 7: Exam I review
  • Fri, Feb 9: Exam I (Chapters 1-4)
  • Mon, Feb 12: Repetition I (while loops) [ while.py ] (Chapter 7)
  • Wed, Feb 14: Functions I [ functions.py ] (Chapters 5 and 6)
  • Fri, Feb 16: Functions II [ functions.py ]
  • Wed, Feb 21: While practice, functions III [ collatz.py ]
  • Thu, Feb 22: String demo
  • Fri, Feb 23: More while & function practice, tracing with functions [ box-functions.py, tracing-example.py ]
  • Mon, Feb 26: Lists [ lists.py ]
  • Wed, Feb 28: Lists, reference, and for loops [ lists.py ]
  • Fri, Mar 2: Practice reading & writing for loops
  • Mon, Mar 5: Exam 2 review [ exam2-practice.py ]
  • Wed, Mar 7: Exam 2
  • Fri, Mar 9: Recursion [ factorial.py ]
  • Mon, Mar 12: Recursion II [ recursion.py ]
  • Wed, Mar 14: Recursion III [ recursion.py ]
  • Fri, Mar 16: no class
  • Spring break
  • Mon, Mar 26: Dictionaries [ dictdemo.py ] (Chapter 12)
  • Wed, Mar 28: Dictionaries II, File I/O [ dictdemo.py ]
  • Fri, Mar 30: Execution tracing with stack & heap [ dicttrace.py ]
  • Mon, Apr 2: Intro to classes and objects [ Cake.py ]
  • Wed, Apr 4: More classes and objects [ TrafficLights.py ]
  • Fri, Apr 6: no class
  • Mon, Apr 9: More classes and objects [ Cake.py, TrafficLights.py ]
  • Wed, Apr 11: Extended example: Blackjack [ Card.py ]
  • Fri, Apr 13: Blackjack [ Deck.py ]
  • Mon, Apr 16: Blackjack [ Player.py ]
  • Wed, Apr 18: Blackjack [ Blackjack.py ]
  • Fri, Apr 20: Exam 3 review
  • Mon, Apr 23: Exam 3
  • Wed, Apr 25: Queues [ ListQueue.py, QueueTest.py, QueueSpeedTest.py ]
  • Fri, Apr 27: Queues II [ Link.py, LinkedQueue.py ]

Homework and quizzes

There will often be short homework assignments to be completed over the weekend, assigned on Friday and due Monday, along with a corresponding quiz at the beginning of class on Monday.

These quizzes and homework assignments together will comprise 15% of your final grade.

HW Due
0: Who Are You Friday January 19
1: Minecraft Monday January 22
2: Logic puzzles Monday January 29
3: Conditional practice Monday February 5
4: Function reading Wednesday February 21
5: Function, loop, and string reading Monday February 26
6: Heap tracing [ Heap tracing template ] Monday April 2


Much of your experience with programming in this course will be through weekly labs, which will comprise 25% of your final grade. Each lab will be assigned Wednesday/Thursday in lab with time allotted to work through the materials, and will be due by the start of the following lab. All labs are weighted equally within the lab portion of your final grade.

Each student has four late days to spend throughout the semester as they wish. Simply inform me any time prior to the due date for an assignment that you wish to use a late day; you may then turn in the assignment up to 24 hours late. Multiple late days may be used on the same assignment. There are no partial late days; turning in an assignment 2 hours late or 20 hours late will both use 1 late day. Note that late days are intended to cover both normal circumstances (you simply want more time to work on the assignment) and exceptional circumstances (you get sick, travel for a game or family obligation, etc.). Aside from late days, late assignments will not be accepted.

On these labs, you may work with a partner on the lab assignments if you choose. Their name must be listed on any code you hand in as joint work. A partnership need only turn in a single copy of the assignment. If students working as partners wish to turn in a lab late, both students must use a late day.

Lab attendance is required. Labs take place in the Snoddy Computer Lab, in the Bailey Library. As you go through the exterior door of the library, turn immediately to your left and enter the Snoddy Academic Resource Center, through this door:

Continue through the door at the far end of the hall (just visible in the picture above) into the first computer lab, and then enter the second lab at the back.

You will be handing in your lab work electronically. Instructions on how to do so will be included in each lab.

Labs should follow the Python style guide. You may use the automated style checker to help you catch common style errors.

Please submit labs electronically using this form!

Lab Name Assigned
1 Minecraft Hour of Code Jan 17/18
2 Kepler and Newton Jan 24/25
3 Diagnosing Heart Disease Jan 31/Feb 1
4 This Day in History Feb 7/8
5 Guess My Number Feb 14/15
6 Mutation is the Word Feb 21/22
7 Caesar’s Secrets Feb 28/Mar 1
P2 Project 2 start Mar 7/8
8 Fractal Recursion Mar 14/15
9 Sentiment Analysis Mar 28/29
10 Die Hard III Apr 4/5
11 Graphics and Animation Apr 11/12
12 On Stuckness and debugging Apr 18/19


You will have three projects in this course, one about every five weeks, for a total of 35% of your final grade. These projects will cover concepts we have discussed in class and in labs, and will be due approximately one week after they are assigned.

You must work individually on the first two projects. You may discuss concepts and ideas with your classmates, but the code you turn in must be your own. You will be graded not only on correctness, but also technique, documentation and evaluation of your solution. Further details on the grading standards and handin instructions for each project will be given when they are assigned.

Please submit projects electronically using this (same) form!

Project Name Pct Assigned Due
1 Question-Answer 5% Feb 5 Feb 16
2 Word Games 10% Mar 7 Mar 15
[ Sample project start #1, Sample project start #2 ]
3 Final Project 20% Apr 9 Monday, May 7, 8:30-11:30am


There will be three in-class exams, the first worth 5% and the last two each worth 10% of your final grade. They will consist of short answer questions along with writing and debugging code.

There is no final exam; you will complete a final project instead, as described above under Projects.


Your final grade for this course will be based on the Labs, Projects, Quizzes, Exams and Participation described above.

Component Percent
Labs 25%
Projects 35%
Quizzes, HW, participation 15%
Exam 1 5%
Exam 2 10%
Exam 3 10%