Computer saying invalid syntax, but I don't understand why

I am making a tic-tac-toe program that chooses a random spot to play. For some reason, I am getting a syntax error that I do not understand. Here is the result:


It is saying that my variable, comp_choice, has incorrect syntax, but I cannot find why; help would be appreciated, thanks.

Hi @pythonlearner1234543,

It appears that according to the error message, you have an errant comma after comp_choice on line 15, though it is not visible in the code you have displayed. There is a shift to italics in the display of that variable name, though.

First look at the line above, and make sure the parentheses are all closed. A SyntaxError is sometimes related to something on the line previous to where it is reported. Perhaps correcting the parentheses will clear things up. If not, and there really is a strange character right after the variable name on line 15, it might be a good idea to delete that entire line, just to make sure it is clean, and then to type it over again correctly.


Thanks man, but now I get this error. I decided to take out that section and replace it with a for loop. But I get an error:

The details of the TypeError messages that you received indicate that you are attempting to access a function by using an index or key. That is due to your placing square brackets instead of parentheses around the intended arguments during your attempts to call the len function.

Edited on February 2, 2020 to add the following:

Make sure you enclose the arguments in parentheses during those function calls. When you have adjacent sets of parentheses and square brackets, the clutter sometimes causes confusion.

It worked! Thanks!!!

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.