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
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
forloop takes one item at a time from a collection and runs the indented lines for it.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 4solve(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
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.
total += nprint(total)total = 0for n in range(1, 4):
Use the arrows to move a line.