Practice Python

Beginner Python exercises

03 August 2016

Tic Tac Toe Game

Exercise 29 (and Solution)

This exercise is Part 4 of 4 of the Tic Tac Toe exercise series. The other exercises are: Part 1, Part 2, and Part 3.

In 3 previous exercises, we built up a few components needed to build a Tic Tac Toe game in Python:

  1. Draw the Tic Tac Toe game board
  2. Checking whether a game board has a winner
  3. Handle a player move from user input

The next step is to put all these three components together to make a two-player Tic Tac Toe game! Your challenge in this exercise is to use the functions from those previous exercises all together in the same program to make a two-player game that you can play with a friend. There are a lot of choices you will have to make when completing this exercise, so you can go as far or as little as you want with it.

Here are a few things to keep in mind:

As a bonus, you can ask the players if they want to play again and keep a running tally of who won more - Player 1 or Player 2.


Starting this exercise from scratch will take you longer than 30 minutes. The best way to save time is to reuse work that has already been done!

Because you have already done the work of the previous 3 exercises, no need to re-do them all! Simply take your code from those exercises, copy it into a new file, and start again. Even if you lost your code from those exercises, go to the solutions pages, here, here, and here, pick your favorite solutions, and start from those!

A large part of programming is reusing code written by someone else to accomplish a task. Sometimes it is fun to write a solution yourself, but other times you want to build on top of something else. This exercise gives you an opportunity to practice one of the arts of programming - starting from code someone else wrote and creating something on top of it.


To effectively complete this exercise, you will need to make extensive use of functions to accomplish small, modular, tasks within your larger program. Here are some resources about functions in case you get stuck:

If you are new to Python, this might be one of the longest programs you have written so far, so have fun!

Happy coding!

Enjoying Practice Python?

Explore Yubico
Explore Yubico
comments powered by Disqus