Skip to contentSkip to navigation

Python, one line at a time

Three courses take you from your first print() to your own classes and generators. You learn by running the code, changing it and fixing what breaks.

evens.pystep 13 of 13

numbers = [3, 8, 5, 12]
total = 0
for n in numbers:
if n % 2 == :
total += n
print(total)done

line 6: done

Trace table: n, n % 2 and total after each turn of the loop
nn % 2total
310
808
518
12020

Output: 20

Change the 0 on line 4, then step through it again.

Lessons and the playground open without an account.

What a free ID keeps

Write it, run it, fix what breaks

  1. Write it

    The editor is in the lesson. You type the lines yourself.

  2. Run it

    Real CPython runs in the page and answers at once.

  3. Read the error

    The last line says what went wrong. Line 2 is where.

  4. Fix it

    One letter is missing. Type it and run it again.

  5. Pass

    The tests say what is right, and your ID keeps the result.

A program with a misspelled name is run. The traceback names line 2, the missing letter is added and every test passes.

main.py

Every lesson is the same loop

Read it, run it, change it, prove it. You always know what comes next, so the only new thing is the Python.

every_lesson.py

for lesson in course:
  1. read(lesson.idea)

    One idea, in plain words

    A lesson teaches a single thing. Here is the one behind the loop you just traced.

    A for loop takes one item at a time from a collection and runs the indented lines for it.

  2. run(lesson.example)

    An example you can change

    Every example is an editor with a Run button. Real CPython answers, in the page, with nothing to install.

    example.py
    for word in ["red", "green", "blue"]:
        print(word, len(word))
    
    Output: red 3 green 5 blue 4
  3. solve(lesson.lab)

    A Lab you solve yourself

    420 tasks in 7 kinds, easy to hard: write it, fix it, predict it, trace it. Tests tell you what is still wrong.

    fix_it.py Practice saved
    # add up the even numbers
    numbers = (3, 8, 5, 12, 7, 10)
    total = 0
    for n in numbers:
        if n % 2 == 0:
            total += n
    print(total)
    
    Output: 30
    • Prints 30, passed
    • Skips the odd numbers, passed
    • Keeps the for loop, passed
  4. answer(lesson.quiz)

    A quiz the server marks

    720 questions in 9 kinds. The answer keys stay on the server until you finish, and every code answer was run in real Python first. Try one.

    Put the lines in order so the program prints 6.

    1. total += n
    2. print(total)
    3. total = 0
    4. for n in range(1, 4):

    Use the arrows to move a line.

The whole path, seen from far away

60 lessons in 18 modules across three courses. Each line is a lesson. They are all open from the start, so begin where you need to.

The courses in numbers

60 lessons. 420 Lab tasks. 720 quiz questions. Score 80% on a course final and the certificate carries your name.

What counts, and what it is worth

XP is paid once for verified learning: lessons, quizzes and exams. A season lasts 4 months and each course keeps its own board.

See the leaderboard
XP for each kind of verified learning
Complete a lesson5 XP
Each correct answer in a lesson quiz2 XP
A perfect lesson quiz+6 XP
Pass a module exam at 80%40 XP
Pass a course final at 80%150 XP
Lab practice0 XP
Score 80% or more on a course final and the certificate is issued in your name.Check a certificate

What an ID gets you

Your progress, quiz marks and files stay with you on any device. The course itself is open without an account.

  • It remembers where you stopped

    Finished lessons are ticked off, and Home points at the next one.

  • Your marks are kept

    Quiz attempts and practice results stay, with the answers you gave.

  • A drive for your own files

    Keep your own .py scripts and notes, up to 10 MB per file.

  • Wrong answers come back

    Questions you miss return in a review queue, spaced out over days.

  • Streak, XP and a leaderboard place

    Verified learning earns XP and a season board place; Lab practice earns none.

  • Notes that stay put

    Write notes on any lesson and find them all on your Notes page.

  • 20 badges and a certificate

    Badges as you go, and a certificate for each course final you pass at 80%.

  • The same place on every device

    Progress is stored against your ID, so your phone and laptop agree.

  • No email address
  • Three things to type
  • Under a minute
  • Free, with no card

Your first program is one line long