In 3 previous exercises, we built up a few components needed to build a Tic Tac Toe game in Python:
The next step is to put all these three components together to make a two-player Tic Tac Toe game!
This exercise is unique because it relies on the output of the other exercises that need to be put together to make the final solution. The goal is to get practice with functions and how they work together in larger programs.
The 3 exercises above suggest breaking your Tic Tac Toe game into (at least) 4 functions:
The way to solve this problem is to look back at all 3 solutions to the previous exercises, copy them into one file, and modify what you had before. This is a different way of coding than coding an entire program from scratch, and can often save a lot of time.
For my solution, I decided to copy all the functions from the older exercises into one file, and work from the main game logic from Part 3. Part 3 almost made you write the entire game - the main loop asking users for positions and input is already there, so starting from that point and modifying will let you finish this exercise in 30 minutes!
After some modifications:
The final product is here:
Happy hacking!comments powered by Disqus