GitHub - tklinge/ThinkPython: A derivative of Think Python by Allen Downey, published by O'Reilly Media, with some enhancements for self-directed learning via a Github Education account. · GitHub
Skip to content

About

A derivative of Think Python by Allen Downey, published by O'Reilly Media, with some enhancements for self-directed learning via a Github Education account.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Think Python — Self-Directed Learning Edition

Think Python: How to Think Like a Computer Scientist (3rd edition) by Allen B. Downey, adapted for self-directed learning with AI pair-programming assistants.


How to Use This Repository

This course is designed for self-directed learning with GitHub Copilot (or a compatible AI coding assistant) in VS Code.

  1. Open this repository in VS Code
  2. Start at Chapter 1 (Setup) and work through chapters in order
  3. Read each chapter's markdown reading file
  4. Practice in the VS Code Python REPL, by running the chapter's example programs in its examples/ folder, or by writing your own scripts
  5. Ask Copilot for help with exercises — each chapter has tailored coaching instructions

No Jupyter notebooks required. No build step. Just read, code, and practice.

Tip: Code exercises live in exercises/ folders as scaffold files you can run to check your work — most include doctests, a few are visual turtle programs or runnable scripts. Each chapter's examples/ folder has practical mini-programs built only from that chapter's concepts — run them to see the pieces fit together. They never contain exercise solutions; ask your AI assistant for hints, not answers. Each chapter's reading opens with a short table of contents and closes with links to its exercises, examples, and the next chapter.


Try It in 5 Minutes

# 1. Clone and open the repository in VS Code
git clone https://github.com/tklinge/ThinkPython.git && code ThinkPython
# 2. From the chapter folder, run a worked example (Chapter 4: Functions)
cd ThinkPython/chapter04 && python3 examples/tour_poster.py
# 3. Run that chapter's worked-example doctests — you should see "Test passed."
python3 -m doctest examples/merch_stand.py -v | tail -3
# 4. Now run an exercise scaffold. Its doctests are the spec for code you
#    haven't written yet, so they fail — that red is the thing to fix.
python3 -m doctest exercises/ex01_print_right.py | head -5
  1. Open chapter04/exercises/ex01_print_right.py in the editor, and in Copilot Chat (with the #file reference attached) ask: "Give me a hint for exercise 1, not the solution." The chapter's coaching instructions tell the assistant to make you predict, run, and explain before it gives anything away.

Design Note: Why the Tutor Won't Give You the Answer

The interesting part of this repository is not the markdown — it is the arrangement that keeps an AI assistant from doing the exercise for you:

  • Reference solutions are agent-only. Each chapter's .github/instructions/chapterXX.instructions.md carries a ## Reference Solutions section. The coach checks your work against it and never shows or pastes it.
  • Doctests are the executable spec. The verdict on your code comes from doctest, not from a model's opinion. Scaffold doctests are written so that a correct solution passes them.
  • Coaching flows are Socratic and per-exercise. Each instructions file maps exercises 1:1 to the reading's numbered exercises, with File: refs, and escalates to hints only when you ask.
  • Concept boundaries. Chapter N's examples use only constructs taught through chapter N — no f-strings before chapter 14, no dict before chapter 11 — so the assistant cannot solve your exercise in vocabulary you have not met yet.
  • Examples never contain exercise solutions. They are worked programs in the chapter's own vocabulary, safe to open.

These are prompt-level guardrails, not enforced sandboxing: they shape what a well-behaved assistant does, and a determined learner can still ask for the answer. The scaffolds make the honest path the easy one.


AI Attribution

This adaptation was drafted with an AI coding assistant working under human direction, and the human is the author of record for the pedagogical decisions: what a chapter teaches, which exercise goes where, how much the coach is allowed to give away. The model's drafts were accepted, rewritten, or thrown away to match those decisions, not the other way round.

The toolchain was pi, a coding agent. The earliest passes ran it directly; later work — including the pass that added this paragraph — ran on the PiDelegation conductor/worker extension, where a conductor model plans a pass and dispatches bounded tasks to worker models that report back with evidence. PiDelegation began in August 2026, two months into this adaptation, and grew against this book's ongoing editorial work rather than a demo — which makes this repository its testbed in the plainest sense: not a project built to show the tool off, but the real work the tool had to supervise.

The models are open-weight Qwen 3.8 checkpoints served locally on self-hosted hardware, with no cloud API in the loop. No single model wrote this, and the log says so: every commit of this edition's own work carries a Co-Authored-By: trailer naming the model that did that commit's work — most of the adaptation was done by Qwen 3.8 27b, recent passes by Qwen 3.8 Flash Next — while the commits inherited from upstream carry no such trailer, because they are Downey's. Count them yourself rather than trusting any number this file might quote: git log --format=%b | grep '^Co-Authored-By:' | sort | uniq -c.

The division of labor: the assistant drafted most of the edition's own material — the added sections of the readings, the example programs, the exercise scaffolds and their doctests, the coaching-instruction files — ran things, and reported back; the human set the direction, reviewed every word and file that landed, and cut. The check on the code is that it was run: every transcript in a reading, every program in an examples/ folder, and every doctest here has been executed before it was committed, and many of the commit bodies record the commands and the counts. You can re-run all of it from a fresh clone with no install step. That is an account of how the work was done, not a warranty — a defect that survived a run is still a defect, and the log is public so you can find where one came from.

Naming these modifications is part of satisfying CC BY-NC-SA 4.0, which requires an adapter to "indicate if You modified the Licensed Material." The per-chapter ## Attribution sections indicate what changed in Downey's text; this section indicates how the edition was made. Neither implies any endorsement by Allen B. Downey or Green Tea Press — see LICENSE.md.


Status

All 20 chapters are complete: readings, example programs, exercise scaffolds, coaching instructions, and licensing. The readings follow upstream's content and chapter numbering (repo chapter N = book chapter N−1).

Everything runs from a fresh clone with no install step — python3 and the files in this repository are the whole toolchain. Run example programs from their chapter folder (cd chapter08 && python3 examples/letter_counter.py); the turtle drawings need a graphical display, and the prompt-driven ones read from the terminal, so they stop with EOFError if you close their input. Doctests are how this book checks its own work and yours:

cd chapter08 && python3 -m doctest examples/letter_counter.py -v   # passes: this code works
cd chapter08 && python3 -m doctest exercises/ex01_uses_none.py     # fails: that code is yours to write

CHANGELOG.md records what this edition changes in Downey's original; LICENSE.md records what is covered by which license.

Every example-bearing chapter is themed (the list is in CHANGELOG.md); each chapter's theme is chosen so the capability that chapter adds is what the program is doing — regular expressions drive the newspaper copy desk in ch09, dictionaries fill the lexicographer's drawers in ch11, tuples get unpacked all over the puzzle night in ch12, shelve keeps the archive's index alive between runs in ch14, and mutation is the plot of the night depot in ch15.


Course Coverage

This book covers the material typically found in an undergraduate CS1 course, including:

  • Programming fundamentals and problem-solving
  • Control structures (conditionals, loops)
  • Functions and modular programming
  • Data structures (lists, dictionaries, tuples)
  • Object-oriented programming basics
  • File handling and data processing
  • Debugging and testing strategies

Learning Approach

This book is designed for self-driven learning without the need for an instructor. You are the primary driver of your learning journey:

  • Work through chapters at your own pace
  • Pause and reflect on concepts as needed
  • Revisit challenging topics without feeling rushed
  • Customize your learning path based on your interests

The Role of GitHub Copilot

Each chapter has tailored Copilot instructions (in .github/instructions/) that guide the AI assistant to coach you through exercises using a Socratic approach:

  • Prediction — try to predict what code should do before running it
  • Experiment — run your code and observe the actual result
  • Observation — compare your prediction with what happened
  • Explanation — ask Copilot for a hint, not the full solution

Chapter Guide

Each chapter's folder holds its reading, an examples/ folder of worked programs, and an exercises/ folder of scaffolds. Work through them in order. The chapter number links to its reading and the exercise count to its exercises/ folder; repo chapter N = book chapter N−1.

Ch. Book Topic Example programs Exercises Level
1 — Setup test_setup.py — Foundational
2 1 Programming as a Way of Thinking mission_control.py — Foundational
3 2 Variables and Statements pizza_party_planner.py 5 Foundational
4 3 Functions merch_stand.py, showtime_countdown.py, tour_poster.py 6 Foundational
5 4 Functions and Interfaces shapes_kit.py, snail.py 5 Foundational
6 5 Conditionals and Recursion fractal_tree.py, guess_the_number.py, rocket_launch.py 4 Foundational
7 6 Return Values hero_map.py, leap_year.py, recursive_math.py 5 Intermediate
8 7 Iteration and Search collatz_counter.py, letter_counter.py, word_list_report.py 6 Intermediate
9 8 Strings and Regular Expressions house_style.py, night_desk_report.py 4 Intermediate
10 9 Lists backpack.py, map_sections.py, word_vault.py 4 Intermediate
11 10 Dictionaries answer_box.py, headword_tally.py, letter_index.py 5 Intermediate
12 11 Tuples cipher_wall.py, judge_scores.py, pair_up.py 6 Intermediate
13 12 Text Analysis and Generation the_impersonator.py, verbal_fingerprint.py, vocabulary_range.py 3 Intermediate
14 13 Files and Databases collection_checksums.py, holdings_config.py, index_shelf.py 3 Intermediate
15 14 Classes and Functions depot_clocks.py, fare_desk.py, shared_probe.py 4 Advanced
16 15 Classes and Methods bakery_clock.py, till_totals.py 2 Advanced
17 16 Classes and Objects arcade_screen.py, world_builder.py 5 Advanced
18 17 Inheritance four_hands.py, the_deck.py, who_says_so.py 7 Advanced
19 18 Python Extras deck_fairness.py, order_form.py, test_word_extras.py (unittest suite), word_extras.py 6 Advanced
20 19 Final Thoughts — — Foundational

Chapter 2's exercises are REPL drills inside the reading, and Chapter 20 has none, so neither has an exercises/ folder.

About

A derivative of Think Python by Allen Downey, published by O'Reilly Media, with some enhancements for self-directed learning via a Github Education account.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages