"Shall we play a game? Before we connect this microcontroller to the global internet, you must prove you can build a closed-loop, interactive system. This is your first real dopamine hit: pure logic turned into a playable simulation."
This project synthesizes everything you have learned so far: variables, loops, functions, lists, and crucially, the error handling. We are building a fully playable, two-player Tic-Tac-Toe game that runs directly inside the Thonny shell.
We aren't just writing spaghetti code. We are engineering a state machine. The game relies on four distinct "Lego Blocks" of logic snapping together:
The board is just a standard Python list containing 9 elements, representing slots 1 through 9. As players make moves, we overwrite the numbers with an "X" or an "O".
board = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]A function that clears the mental clutter and prints the board list into a beautiful, human-readable 3x3 grid in the console.
Users are unpredictable. If you ask for a number and they type the letter "A", a normal script will crash. We use a try/except block to catch the ValueError, scold the user, and keep the game running flawlessly.
After every single turn, a function checks all 8 possible winning combinations (3 rows, 3 columns, 2 diagonals). If it finds three matching symbols, it halts the loop and declares a victor.