4.0 Final Challenge

Lesson

4.0 Final Challenge

Your final challenge for the Python Grey Hat course is to use all of the skills you have learnt so far to create a Tic Tac Toe game against the computer.

Be creative and make it however you want, but it must do the following:

1.      Allows the player to input whether they want to be an X or O and assign the other value to the computer.

2.      Each time it is the computer’s turn, randomly select the computer’s move.

3.      Only allows the computer and user to pick moves that haven’t already been chosen.

4.      After every turn, show the player the updated board.

5.      Keep track of the available moves and the moves taken and checks whether there is a winner or if the board is full (no winner) after every turn.

Hints:

1.      To get the player’s choice for moves and which letter you can use the input() function that you learnt in the python black hat course.

Note: Everything that you receive from input() will be formatted as a string, so if you’re checking it against an integer (number) be sure to convert it to an input too using int(input())

2.      You can use a while loop to perform each turn (use a conditional to check whose turn it is!) – this will prevent you from having to rewrite lots of code!

3.      If you are unsure of how to structure your board you may want to use this example:

4.      To generate a random move for the computer you may want to use python’s random library. You can add import random at the beginning of your code to import the library and when you want to pick a random move you can use move = random.choice() and put a list of all the moves you want to randomly choose from inside of the ‘()’ brackets
You can read more about the random library here:  https://docs.python.org/3/library/random.html

Good luck! 

@

Not recently active