In this lesson, you’ll get instructions on how to solve your first task of the coding challenge. Along the way, you’ll revisit the recommended workflow for using pytest
to receive automated feedback and read a brief summary of the key concepts at the end.
Steps to Complete the Task
After carefully reviewing the task requirements and ensuring you understand what’s expected, you can begin working on a solution. This will help you align your solution with the acceptance criteria. Here are the recommended steps to follow when solving a task.
Step 1: Reveal the Acceptance Criteria
Open the terminal now and run the pytest
command to check the acceptance criteria for the unlocked tasks:

Because you haven’t implemented the wordcount
command yet, the current task will initially show as failed. You’ll fix it now!
Step 2: Update the wordcount.py
File
Switch back to your code editor and open the wordcount.py
placeholder file located in the src/
folder within your project. To help you get through the first task, you’ll find some useful comments there:
src/wordcount.py
# Uncomment the main() function below to solve your first task:
# def main():
# pass
Go ahead and uncomment the main()
function by removing the hash symbol (#
) at the beginning of the highlighted lines. You can also remove the first line if you want to, which would result in the following code snippet:
src/wordcount.py
def main():
pass
You’ve just defined an empty main()
function, which is enough to make the wordcount
command return successfully with a zero exit status code. This command is already mapped to your main()
function through the pyproject.toml
file, so there’s nothing else left to do:
pyproject.toml
# ...
[project.scripts]
wordcount = "wordcount:main"
Thanks to this setup, you can now run the wordcount
command (without the .py
extension) in the terminal:
(venv) $ wordcount
If the command exits without printing anything in the output, then it’s a good indication that everything went fine. Otherwise, you might see a Python traceback similar to this one:
(venv) $ wordcount
Traceback (most recent call last):
File "/home/vscode/.local/bin/wordcount", line 5, in <module>
from wordcount import main
ImportError: cannot import name 'main' from 'wordcount' (/.../wordcount.py)
The error above means that Python couldn’t find the main()
function in your wordcount.py
module.
Note: If you’re solving this challenge locally, then double-check if you’ve activated the project’s virtual environment and that you’ve installed it using the editable mode mentioned earlier.
After making this change, save the wordcount.py
file and return to the terminal.
Step 3: Verify Your Solution
You can run the pytest
command again to verify that the task is now marked as completed:

Well done! Since you’ve satisfied the only acceptance criterion for this task, you’ve been automatically promoted to the next task. To read its instructions, click on the link displayed in the terminal or go to the next lesson. You can also run the pytest --task
command.
Summary
You’ve solved this task by defining a Python function called main()
in your wordcount.py
file. This function doesn’t take any arguments or return a value. Because functions in Python can’t have an empty body, you plugged it with a pass
statement as a placeholder to avoid a syntax error.
The main()
function is hooked up to the wordcount
command in the shell through the pyproject.toml
configuration file. This mapping takes effect when you install your Python project with pip
. If you installed it before in the editable mode using pip -e
, then you don’t need to reinstall it. If you created a GitHub Codespace for this challenge, then the project will have been already installed for your convenience.
What’s Next?
Alright. Now that you’ve gotten acquainted with the recommended workflow and have seen one way of using the pytest
-based automation tool, you can try solving the second task on your own. Good luck!
🎯 Jump into the next lesson to get started with your next task.