Learn Python by making a game

Most beginners quit Python because the exercises feel pointless: print a sentence, add two numbers, forget it. A project changes that, because every new idea does something you can see. In Python DailyDrills you start with Pip, a robot with every system offline, and each chapter ends with a mission where your own code brings one more part of the game to life.

Your first line gives Pip a voice

In the first lesson Pip cannot speak. You fix it with print(). When you open the game, Pip says what your code printed. The point is that the game is not decoration: it runs your code.

print("Hello, I am Pip!")

Output:

Hello, I am Pip!

Conditionals give Pip legs

Pip keeps walking into the sea until you write can_move(). The game calls your function on every step: water and walls say no, everything else says yes. This is how if statements and return values stop being abstract.

def can_move(tile):
    return tile not in ("water", "wall")

print(can_move("grass"))
print(can_move("water"))

Output:

True
False

Dictionaries let the machines talk

The island's machines say whatever your dialogue dictionary holds. Changing a line of text in your code changes what they say in the game.

dialogue = {"villager": "Welcome!", "mechanic": "Bring me scrap."}
print(dialogue["mechanic"])

Output:

Bring me scrap.

Classes build the glitch Pip fights

In the classes chapter you write the Glitch class that the battle uses: hit points, taking damage, and knowing when it is dead. Every Attack in the game calls your method.

class Glitch:
    def __init__(self, hp):
        self.hp = hp

    def take_hit(self, damage):
        self.hp = max(0, self.hp - damage)

glitch = Glitch(12)
glitch.take_hit(4)
print(glitch.hp)

Output:

8

Keep the game you built

At the end you can download the game as a zip. It contains your own code in one file per mission, plus a small engine to run it: python play.py in a terminal, or open play.html in a browser. The download is built in your browser, and your code never goes to a server.

Common questions

Do I need any experience to start?
No. The first lesson starts from print(), and every concept is introduced with small exercises before the mission that uses it.
Is it a real game or just a puzzle?
It is a small top-down game: you walk Pip around an island with the arrow keys, repair machines, scan sensors and fight a glitch. Every ability exists only because you wrote the Python for it.
Does my code run on your servers?
No. Python runs inside your browser, and your mission code is stored in your browser only. The downloadable game is built on your computer too.

Practise it