Coding exercises

Plain Python, one challenge at a time

No game this time: a challenge to read, an editor for your code, and tests that tell you the moment it works. From your very first print to programs that read and write files.

The first five challenges are open to everyone: no account needed.

How a challenge works

  1. 1

    Read it

    What to make, an example of what it prints, and hints one at a time when you need them.

  2. 2

    Write it

    The editor helps as you type: what each command does, in your own language. Run it as often as you like.

  3. 3

    Check it

    Check runs the tests. Each one says what it expected and what it got, until every one passes.

Step by step

The challenges come in groups, each a topic, each a little harder than the one before.

  1. 1Python basicsClassic challenges: printing, input, numbers, if, loops, text, functions and files.10
  2. 2Printing and variablesThe first steps: print text and numbers, keep values in variables, and put them together.8
  3. 3Input and arithmeticAsk for numbers, turn text into numbers, and calculate: whole parts, remainders and decimals.8
  4. 4ConditionsLet the program choose: if, elif and else, comparing numbers, and joining conditions with and / or.9
  5. 5LoopsDo it again: for and range, while, adding up as you go, counting, and loops inside loops.10
  6. 6TextWork with words: letters by their place, slices, upper and lower case, counting, splitting and joining.9
  7. 7ListsMany values under one name: read a line of numbers, add them up, find the largest, pick some out, sort them.9
  8. 8FunctionsName a piece of code and use it again: def, parameters, return, and functions that use each other.8
  9. 9Dictionaries and setsLook things up by a name: dictionaries for counting and grouping, sets for what's different.9
  10. 10FilesRead data from a file and write answers to another: lines, numbers in rows, a count first, CSV.8
  11. 11AlgorithmsThe classics, by hand: the smallest and largest, searching, sorting, binary search, primes, GCD and other bases.10
  12. 12Exam practiceWhole exam-style challenges: a data file in a set format, several steps, and the answer written exactly as asked.7
  13. 13OlympiadFirst rounds of the olympiads: an idea makes it quick. Windows, prefix sums, a stack, greedy choices and counting in one pass.8

Debug

Watch your code run

Debug runs your program one step at a time: the line it's on lights up, and every variable shows what it holds right then.

  • Steps back and forth, or straight to a line
  • Lists and dictionaries drawn as boxes
  • Errors explained next to their line

Projects

Make something of your own

A project is Python with no tests and no rules: as many files as you like, input() and output, saved with your account. Start empty or from an idea.

Start a project
  • BlankJust main.py
  • Text adventureRooms, and input() to walk between them
  • CalculatorTwo numbers, and what to do with them
  • GradesA CSV read, and a report written

Python guide

Look anything up

The Python guide explains every idea with an example and exactly what it prints, in five parts.

Python guide
  1. 1Foundations7 topics
  2. 2Data6 topics
  3. 3Functions and errors6 topics
  4. 4Objects5 topics
  5. 5Programs and systems5 topics

For teachers

Write challenges of your own with their tests, give them to a class, follow each student's code in a live lesson, and play back how it grew.

See the teacher's view

Your first challenge takes a minute

Print one line, press Check, and see the tests go green.

Try the first challenge