PY-1.4-BP6-MQ30

Our Goal: Make Your Code Easy to Understand

In this lesson, you will make your game code easier to understand. You will add special notes, called 'comments', to your Python code. These comments will explain what different parts of your game do, like the main parts of your game and any special rules or actions. This helps you and others know what your code is doing.

Get Ready to Add Comments

Before you add comments, open your main.py file. Read through your game code.

Think about which parts of the code are hard to understand. These are the places where you should add comments. For example, if you have a special rule in your game, you can add a comment to explain it.

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 important parts of your code, like where you set up the game, where you handle player actions, and where the game rules are. Add comments to explain what these parts do.

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 why your code does something, not just what it does.

Check Your Work Again

You've added comments to your code! Now, let's check to make sure they are good.

  1. Read through your main.py file again. Look at the comments you added.
  2. Are the comments clear and easy to understand? Do they explain what the code does?
  3. Run your game to make sure it still works after adding the comments.

Run this command in your terminal to check the tests:

pytest module-1.4/blueprint-BP6/quest-30

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-BP6.