Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple tictactoe with error
#1
Hi. Kind of a novice at this. Trying to finish up a tictactoe program. I know there were better ways to go about some things, but I was trying to just work with what I could remember. I am having a serious problem now, though. I keep getting a syntax error I don't understand. If someone could help me out it would be greatly appreciated.
#tictactoe game practice
print ("Hello! I guess you want to play the age-old game of tic-tac-toe, with it's very \n"
       "few options for victory! If you would like to make a move, you simply enter a number \n"
       "between one and nine, with the spots being read left to right and down, like a book.\n"
       "You then press enter. Well, Here you go! Hope you have fun.")


#Where all the values of the game board are stored
game = ["."]*9

game_over = False
#Drawing the game board
def draw_game(game):
    print (" _________________")
    print ("| ", game[0], " | ", game[1], " | ", game[2], " |")
    print (" _________________")
    print ("| ", game[3], " | ", game[4], " | ", game[5], " |")
    print (" _________________")
    print ("| ", game[6], " | ", game[7], " | ", game[8], " |")
    print (" _________________")

def input_user_data(game):
    game[int(input("Where would you like your 'O'?"))-1] = "O"
    draw_game(game)
    if "." in game:
        game[int(input("Where would you like your 'X'?"))-1] = "X"
        draw_game(game)

def check_winner(game):
    if game[0] == "X" and game[1] == "X" and game[2] == "X":
        return 2
    elif game[3] == "X" and game[4] == "X" and game[5] == "X":
        return 2
    elif game[6] == "X" and game[7] == "X" and game[8] == "X":
        return 2
    elif game[0] == "O" and game[1] == "O" and game[2] == "O":
        return 1
    elif game[3] == "O" and game[4] == "O" and game[5] == "O":
        return 1
    elif game[6] == "O" and game[7] == "O" and game[8] == "O":
        return 1
    elif game[0] == "O" and game[3] == "O" and game[6] == "O":
        return 1
    elif game[1] == "O" and game[4] == "O" and game[7] == "O":
        return 1
    elif game[2] == "O" and game[5] == "O" and game[8] == "O":
        return 1
    elif game[0] == "X" and game[3] == "X" and game[6] == "X":
        return 2
    elif game[1] == "X" and game[4] == "X" and game[7] == "X":
        return 2
    elif game[2] == "X" and game[5] == "X" and game[8] == "X":
        return 2
    elif game[0] == "X" and game[4] == "X" and game[8] == "X":
        return 2
    elif game[0] == "O" and game[4] == "O" and game[8] == "O":
        return 1
    elif game[2] == "O" and game[4] == "O" and game[6] == "O":
        return 1
    elif game[2] == "X" and game[4] == "X" and game[6] == "X":
        return 2

draw_game(game)
while game_over != True:
    winner = check_winner(game)
    if "." not in game:
        print ("No more spaces!")
        game_over = True
    if winner == 1
        print ("Player one wins!")
        game_over = True
    if winner == 2
        print ("Player two wins!")
        game_over = True
    else:
        input_user_data(game)

else:
    print ("Game over!")
Reply
#2
If statements have to end with a colon (:), just like the one above it on line 67.

In the future, please post a full copy of the traceback (the error text). That way we can diagnose the problem without having to copy, paste, and run your code.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Wow. I can't believe I missed that. Thanks for taking the time on such a simple thing.
Also, I will take note of the traceback error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Array in tictactoe machine not working? Illumimint 4 1,562 Jun-02-2022, 02:24 AM
Last Post: Illumimint
  TicTacToe Game Add Exception Handling and Warning Function ShaikhShaikh 5 2,376 Nov-03-2021, 05:02 PM
Last Post: deanhystad
  Simple code error please help bntayfur 7 3,392 Jun-08-2020, 02:22 AM
Last Post: pyzyx3qwerty
  Adding second message to simple loop error PythonGainz 2 2,055 Apr-06-2020, 11:55 AM
Last Post: PythonGainz
  TicTacToe PC vs PC harig3 3 2,203 Mar-28-2020, 01:13 PM
Last Post: harig3
  Beginner - simple package installation error mefeng2008 0 1,699 Mar-13-2020, 09:17 AM
Last Post: mefeng2008
  Simple python code error cls0724 5 3,271 Mar-12-2020, 07:45 PM
Last Post: stullis
  Error with simple "or" statement? Mark17 4 2,266 Nov-15-2019, 05:16 PM
Last Post: Mark17
  Simple question - ERROR UnitedK 1 2,372 Sep-24-2018, 11:11 AM
Last Post: wavic
  Can't figure out the syntax error, relatively simple code maho686868 3 3,082 Jul-08-2018, 03:43 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020