Python Forum
Simple tictactoe with error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Simple tictactoe with error (/thread-2152.html)



Simple tictactoe with error - mut4ntch1ck - Feb-22-2017

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!")



RE: Simple tictactoe with error - ichabod801 - Feb-22-2017

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.


RE: Simple tictactoe with error - mut4ntch1ck - Feb-22-2017

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.


This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.