Summary
This subject is an introduction to computer programming using the Python language, aimed at beginners with no prior coding experience. It teaches students to think like computer scientists: breaking problems into steps, writing precise instructions, and finding and fixing mistakes. Concepts are introduced gradually, with case studies that apply each new tool to a realistic problem.
The opening chapters, The Way of the Program, Variables, Expressions and Statements, and Functions, explain what a program is and cover the building blocks: assignment, operators and their order of evaluation, the three kinds of errors (syntax, runtime, semantic), type conversion with int, float, and str, and defining functions with def. Students learn about parameters, return values, local variables, and stack diagrams. Case Study: Interface Design uses turtle graphics to practice encapsulation, generalization, refactoring, docstrings, and pre- and postconditions. Example tasks include drawing polygons with an exterior angle of degrees.
Conditionals and Recursion, Fruitful Functions, and Iteration cover control flow. Students use floor division (//) and modulus (%), write functions that return values, and build recursive definitions such as and . They also practice incremental development and the "leap of faith." The iteration chapter introduces while loops, break, and Newton's method for square roots, , with a warning not to test floats for exact equality.
The data-structure chapters, Strings, Case Study: Word Play, Lists, Dictionaries, Tuples, and Case Study: Data Structure Selection, form the core of the subject. They cover indexing, slicing, and immutability, along with search and counter patterns. Lists bring mutability, aliasing, and map/filter/reduce. Dictionaries cover hashing, memoization, and inverting a mapping, while tuples cover packing, unpacking, and gather/scatter. The case studies apply these tools to word puzzles (palindromes, abecedarian words), word histograms, and Markov text generation.
Files explains reading and writing files, relative and absolute paths, the % format operator, and catching errors with try/except. The object-oriented chapters, Classes and Objects, Classes and Functions, Classes and Methods, and Inheritance, introduce programmer-defined types, attributes, shallow and deep copying, and pure functions versus modifiers. They also cover invariants, methods, operator overloading such as __lt__, and parent-child class relationships.
The closing chapters round out the course. The Goodies presents shortcuts: conditional expressions, list comprehensions, generator expressions, sets, Counter, defaultdict, any, and all. Debugging sorts common exceptions (NameError, TypeError, KeyError, IndexError) and explains how to read a traceback. Analysis of Algorithms shows how to predict an algorithm's time and memory use as input grows.
Key ideas:
- A program is a precise sequence of instructions; errors are syntax, runtime, or semantic.
- Functions package reusable code, and good interfaces hide unneeded details.
- Recursion needs a base case and calls that move toward it.
- Loops must change something so their condition eventually becomes false.
- Strings and tuples are immutable; lists and dictionaries are mutable, so aliasing matters.
- Dictionaries map hashable keys to values and allow very fast lookups.
- Classes define new types whose objects bundle data (attributes) with behavior (methods), and inheritance lets classes reuse code.
- Testing and systematic debugging are core skills, not afterthoughts.

