Home › Learn by Playing › Python › Fix the Code
Python · Puzzle game · 5 levels
Fix the Code
In Python, the order of lines and the spaces at the start of each line change what a program does. Put the lines in order, fix the indentation, and press Run.
Each dot is one space. Indent and Outdent move a line by 4 spaces, the Python standard. You can also drag the dotted handle: up and down to move, left and right to indent. Keyboard: Shift + arrow keys move a line, Left and Right change the indent.
How to play
- Tap a line to select it. Then use Up and Down to move it and Indent and Outdent to change its spaces.
- Press Run program. You win when your output matches the expected output exactly.
- If Python stops with an error like
IndentationErrororNameError, the yellow box explains it in simple words. - Stars: right first time is 3 stars, one failed run is 2 stars, more is 1 star.
The programs are real Python 3 that you can run on your own computer. The game runs them in a small built-in runner, so the error messages follow real Python but are simplified a little.