How Can Playing a Game Improve Your Python Programming Skills?

Python Challenge was the first programming-puzzle website. Players solve 33 consecutive puzzles that require code, improving their programming skills along the way.

How Can Playing a Game Improve Your Python Programming Skills?

This article was originally written in Chinese and translated into English by AI.

Introduction to Python Challenge

Python Challenge was the first website built around programming puzzles. Players work through 33 consecutive challenges that can only be solved by writing code, sharpening their programming skills along the way. The site was founded in 2005 and has since received more than three million visits.

The official Python Challenge website

The official Python Challenge website

The website looks rather dated and is not especially polished, but its puzzles are remarkably inventive. The real pleasure comes from solving each one on your own, without consulting a guide.

User brberg described it this way:

These sorts of things are in my opinion the best way to learn a language.

User salimma wrote:

Addictive way to learn the ins and outs of Python.. a must for all programmers!

The built-in message board is now overrun with spam, but players can still discuss the challenges through the Google group and consult the community-maintained wiki.

The Python Challenge wiki

The Python Challenge wiki

Python Challenge uses cookies to record your progress. Its official solutions are only available after you have cleared the corresponding level and visited its answer URL.

Official solutions are unlocked only after completing a level

You can view an official solution only after completing the level

The official approaches are also worth studying. Comparing them with your own solution can reveal different ways to think about the same problem and broaden your programming perspective.

Example Challenges

My solutions are available on GitHub. At the time of writing, I had completed 12 of the 33 levels.

You can try the puzzles yourself at Python Challenge. The examples below contain spoilers.

Level 2

The page presents only an image and a short line of text. The first step is to recognize that the letters might be hidden in a book—or somewhere in the page source.

Python Challenge level 2

Opening the source reveals an enormous comment and a hint telling us to find the letters hidden among the clutter.

A large block of characters hidden in the page source

The string is almost 100 KB long. A dozen or so lines of Python are enough to filter it and reveal the answer: equality. Replace the suffix in the address bar with equality.html to enter the next level.

Python code used to solve level 2

Level 4

This level contains only an image, while the page title says “follow the chain.”

Python Challenge level 4

Clicking the image opens a page that says and the next nothing is 44827. Replace nothing=12345 in the URL with the newly supplied number.

The next number in the chain

Repeating the process manually leads to another page with the same kind of instruction:

Another step in the number chain

Clearly, following hundreds of links by hand is not practical. This is a good use case for a crawler and some simple page analysis. I previously introduced the basics of web crawling in this article.

The program repeatedly requests the current page, extracts the next number, and uses it to construct the following URL.

A Python crawler for following the chain

The chain occasionally includes misleading or manually worded instructions, so the program also needs to account for those exceptions.

A misleading instruction in the chain An exceptional instruction in the chain

After visiting more than 200 pages, the chain finally reveals the answer: peak.html.

Level 7

Python Challenge level 7

The image contains an unnatural strip of grayscale blocks. Examining that region more closely gives us the first clue.

Inspecting the grayscale strip

The grayscale values of these blocks are all below 128.

Grayscale values extracted from the image

That range suggests ASCII. Converting the grayscale values into characters produces the hidden message.

Decoding grayscale values as ASCII

The result is:

'smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]'

Decoding the list of ASCII values gives the answer: integrity.

Level 11

The only hint on this page is “odd even.”

Python Challenge level 11

Separate the pixels into two images according to whether the sum of their x and y coordinates is odd or even:

Image formed from one set of odd-even pixels Image formed from the other set of odd-even pixels

The resulting image reveals the password: evil.

More

These examples are only the tip of the iceberg. Some levels require plotting libraries:

A Python Challenge puzzle involving plotting

Some test file handling and input/output skills, with clues hidden in unexpected places:

A Python Challenge puzzle involving files and input-output

Others demand a particularly wild leap of imagination:

A more imaginative Python Challenge puzzle

Python Challenge is an excellent combination of programming practice and puzzle solving. It makes learning Python's details far more engaging than working through isolated exercises.

My GitHub repository includes both the solution code and notes explaining the reasoning and techniques used for each level.

Python Challenge solution notes on GitHub