Getting started

Quiz: counts toward finishing the lesson. Check: just for practice.

Welcome. This course teaches the fundamentals of programming using Python. The focus is on the core ideas (variables, control flow, loops, functions, objects, and data structures), not on clever or optimal Python. Once you have the ideas you can carry them to any language.

How this course works

The course has two halves that work together.

Lessons, here in your browser. Each lesson explains a concept with code you can run. The code runs in the page itself (Python runs in your browser), so there is nothing to install to follow along. Press Run on the code cell below, then edit the code and run it again. A plain code cell like this one is just for trying things. Nothing is graded.

Two other kinds of cell ask you something. Both tell you whether you got it right. The difference is whether they count.

Quizzes count. You write the answer, press Run, and the cell tells you whether it passed, with a message to guide you if it did not. Hints are there when you get stuck. A quiz has a solid orange border, and when you pass it, it turns green. A lesson is finished when you have passed all of its quizzes. Try this one:

  1. Change the code so that the program prints Hello, Python!.
Hint 1

Replace the three question marks with the word Python.

Checks do not count. They are quick questions that help you notice whether an idea sank in. You can skip one, retry it as often as you like, and nothing is recorded. A check has a dashed border, and a lesson that has checks shows a short key under its title. Here is one:

Check your understanding. Predict what this program prints. The program is not run for you. Change output to the text you expect, in quotes.

count = 4
print(count * 2)
Hint 1

The program multiplies 4 by 2 and prints the result.

IDE projects, on your own machine. Each section also has a larger project you build locally in a real code editor (the notes assume VS Code). The in-browser lessons teach the concept; the local project is where you practice building something bigger, the way you would in real work. Setting up an editor and running your own Python files is part of learning to program, so the projects live outside the browser on purpose.

How to move through it

Use the section list on the left to jump between lessons, or the Previous and Next buttons at the bottom of each lesson to go in order. Start with the next lesson and work forward.

How projects work

Every project in this course is written the same way. Read the description, create a file with the name it gives, write your solution, and run it in VS Code. Each project has its own page. You will find it in the sidebar under its section, marked with a small arrow, and in a list at the end of the lesson it follows. Each page also has a collapsible solution with tests. Try the project yourself first.

Before the first project you need Python and a code editor on your computer. Set up your editor walks through it, and the first project, Your first Python file, checks that it works.

Reading the tests

Every project has a solution you can open, and every solution comes with tests. The tests are there to read, not only to run. A good test suite shows what the code is supposed to do, so read the test names first: each one describes a single rule.

The tests use tools you have not met yet, such as classes and the unittest module. Do not worry about how they work. Read the test names and the expected values: together they list what the program must do.

To measure coverage on your own project in the VS Code terminal, install the tool once, then run your tests under it and print the report. The report lists any line your tests missed. (On Windows, use python in place of python3.)

python3 -m pip install coverage
python3 -m coverage run --branch -m unittest
python3 -m coverage report -m

All projects

Every project, in course order. Each name links to its page.

Project Follows the lesson
Your first Python file Set up your editor
Average of five numbers Input and casting
Celsius to Fahrenheit Input and casting
Making change Input and casting
Smallest and largest Loops
Find the factors Loops
Number guessing game Loops
Distance fallen Functions
Fibonacci number Functions
Hailstone steps Functions
Multiply with recursion Recursion
Hailstone steps with recursion Recursion
Taxicab Classes
Find the median Lists
Add a surname Lists
Standard deviation of ages Lists
Square a list in place References
Reverse a list in place References
Count the letters Dictionaries
Words in both Sets
Employee directory Sets
Add Three game (final project) Sets
Builders game (final project) Sets