Inspiration

What it does

How we built it

I built it using Python.


theBoard = {'7': ' ' , '8': ' ' , '9': ' ' , '4': ' ' , '5': ' ' , '6': ' ' , '1': ' ' , '2': ' ' , '3': ' ' }

board_keys = []

for key in theBoard:

board_keys.append(key)

def printBoard(board):

print(board['7'] + '|' + board['8'] + '|' + board['9'])

print('-+-+-')

print(board['4'] + '|' + board['5'] + '|' + board['6'])

print('-+-+-')

print(board['1'] + '|' + board['2'] + '|' + board['3'])

def game():

turn = 'X'

count = 0


for i in range(10):

    printBoard(theBoard)

    print("It's your turn," + turn + ".Move to which place?")

    move = input()        

    if theBoard[move] == ' ':

        theBoard[move] = turn

        count += 1

    else:

        print("That place is already filled.\nMove to which place?")
        continue

    if count >= 5:

        if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ':
            printBoard(theBoard)

            print("\nGame Over.\n") 

            print(" **** " +turn + " won. ****")

            break

        elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ':

            printBoard(theBoard)

            print("\nGame Over.\n")

            print(" **** " +turn + " won. ****")

            break

        elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ': 

            printBoard(theBoard)

            print("\nGame Over.\n")

            print(" **** " +turn + " won. ****")

            break

        elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ':

            printBoard(theBoard)

            print("\nGame Over.\n")

            print(" **** " +turn + " won. ****")

            break

        elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ': 

            printBoard(theBoard)

            print("\nGame Over.\n")

            print(" **** " +turn + " won. ****")

            break

        elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ': 

            printBoard(theBoard)

            print("\nGame Over.\n")

            print(" **** " +turn + " won. ****")

            break

        elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ':

            printBoard(theBoard)

            print("\nGame Over.\n") 

            print(" **** " +turn + " won. ****")

            break

        elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': 

            printBoard(theBoard)

            print("\nGame Over.\n") 

            print(" **** " +turn + " won. ****")

            break 

    if count == 9:

        print("\nGame Over.\n")

        print("It's a Tie!!")

    if turn =='X':

        turn = 'O'

    else:

        turn = 'X'        

restart = input("Do want to play Again?(y/n)")

if restart == "y" or restart == "Y":  

    for key in board_keys:

        theBoard[key] = " "

    game()

if name == "main":

game()

Challenges we ran into

It was a fun challenge.

Accomplishments that we're proud of

I am proud of taking this challenge.

What we learned

I learned building a tic tac toe game.

What's next for Follow Any Tutorial to Build Something New

Build something cool and new.

Built With

Share this project:

Updates