PY-1.4-BP4-MQ10

Our Goal: Explain Your Code

In this lesson, you will make your Pong game code easier to understand. You will add special notes, called 'comments', to your code. These comments will explain what different parts of your game do, like the Ball and Paddle parts, and how the game works step by step.

Check Your Game Code

Before you add comments, let's check your game code. We will run some tests to make sure the basic parts of your game are there.

Run this command in your terminal:

pytest module-1.4/blueprint-BP4/quest-10

What you should see:

āŒ Some tests will fail. This is okay for now! It means the tests are ready to check your comments later.

Add Comments to Your Code

Now, you will add comments to your main.py file. Comments are like notes that explain what your code does. They help you and others understand your game better.

Look for the Ball and Paddle parts of your code. Add comments to explain what each part does. For example, you can explain what the Ball class is for, or what the move function does.

Also, find the main part of your game code (the game loop). Add comments to explain the different steps, like when the game starts, when it checks for player actions, when it updates the game, and when it draws things on the screen.

Here's how you add comments in Python:

# This is a single-line comment

def my_function():
    """This is a multi-line comment (docstring)
    It explains what the function does.
    """
    pass

Remember to explain what your code does, not just how it does it.

Check Your Work Again

You've added comments to your code! Now, let's run the tests to make sure everything is still working correctly.

Run this command in your terminal:

pytest module-1.4/blueprint-BP4/quest-10

What you should see:

āœ… All tests should pass! This means your code is still good, and you've made it easier to understand.

Documentation

Documentation not available for PY-1.4-BP4.