This is your first coding challenge: write a simple command-line Tic-Tac-Toe game in Python that two players can play against each other. Along the way you will practice planning a program before you write it, using program-design tools and splitting your code into small, focused functions. The repository gives you the assignment, a few supporting lessons, and a starter script to build on.
By the end of this repository, you should be able to:
- Break a programming problem into small, well-named functions before writing code.
- Apply program-design tools (flowcharts, requirements, skeleton code) to plan a solution.
- Write pseudocode to outline an algorithm before you implement it.
- Build a working command-line Tic-Tac-Toe game in Python (board display, player turns, win and draw detection).
- Explain what
if __name__ == "__main__"does and use it as a script entry point. - Read Python error messages and stack traces to debug your own code.
| File / Folder | Description |
|---|---|
| 01 - Assignment | The coding challenge: build a command-line Tic-Tac-Toe game, with step-by-step suggestions. |
| 02 - Program Design | Design tools (flowcharts, requirements, pseudocode, skeleton code) for planning a program before you code. |
| 03 - Intro to Pseudocode | A short primer on writing pseudocode to outline an algorithm. |
| Tic Tac Toe | Starter script where you write your game; it already includes the if __name__ == "__main__" entry point. |
| File / Folder | Description |
|---|---|
| Examples | Two small scripts showing how if __name__ == "__main__" behaves when a file is run directly versus imported. |
| Solutions | Reference solution. |
| Assets | Images used in the lessons. |
| pyproject.toml | Project configuration and dependencies. |
| uv.lock | Pinned dependency lock file. |
Note
Throughout these steps, text in angle brackets like <repo-name> is a
placeholder. Replace it, including the < > brackets, with your own
value. For example, cd <repo-name> becomes cd tic-tac-toe.
Click Use this template on GitHub.
When creating the repository:
- Set yourself as the Owner
- Choose a repository name
- Enable Include all branches
- Click Create repository
Important
If you are working in pairs or groups, only one person should complete this step.
If working with teammates:
- Open the repository on GitHub
- Go to Settings → Collaborators
- Add your teammates as collaborators
- Share the repository link with your team
Teammates should accept the invitation before continuing.
Copy the SSH URL from the Code button on GitHub, then run:
git clone <copied-ssh-url>The copied SSH URL will look like
git@github.com:<your-username>/<repo-name>.git.
This installs all dependencies and creates a virtual environment in .venv/,
including the Jupyter kernel (ipykernel).
cd <repo-name>
uv syncNote
Make sure you open VS Code from the project root so it automatically detects
the environment created by uv sync.
Launch VS Code from the terminal:
code .If you want to work interactively, create a notebook (for example scratch.ipynb) and
select the Python environment created by uv sync as the kernel.
Tip
Prototype and test small pieces of your game in notebook cells, then move the working code into tic_tac_toe.py.
Work through the material in order, and plan before you code.
-
Read 01 - Assignment to understand what the game should do.
-
Review 02 - Program Design and 03 - Intro to Pseudocode for planning techniques.
-
Sketch your solution using a flowchart or pseudocode.
-
Implement and test small functions, then move working code into tic_tac_toe.py.
-
Connect your functions inside the
if __name__ == "__main__"block. -
Run the finished game:
uv run python tic_tac_toe.py
- Give your functions explicit, descriptive names.
- Write a docstring for each function explaining how to call it.
- Keep functions short, roughly 4 to 10 lines each.
- Tic-Tac-Toe: Rules and background of the game you are building.
- Python control flow and functions: Official tutorial on loops, conditionals, and defining functions.
- Python
__main__documentation: Official reference for theif __name__ == "__main__"entry point. - Real Python: What does
if __name__ == "__main__"do?: A beginner-friendly walkthrough of the script entry-point idiom. - What is Pseudocode: A complete tutorial on writing pseudocode.
- Real Python: Build a Tic-Tac-Toe game: A more advanced, GUI-based take on the same game for when you want to go further.
- Real Python: Docstring: A guide to writing and using docstrings in Python.