13/19, Need help!

Write your code below!

if guess_row==ship_row and guess_col==ship_col:
print “Congratulations! You sank my battleship!”
if guess_row not in range(len(board)) or
guess_col not in range(len(board)):
print “Oops, that’s not even in the ocean.”

    print "You missed my battleship!";

elif board[guess_row][guess_col]=='X':
    print "You guesses that one already"     


File “python”, line 40
elif board[guess_row][guess_col]==‘X’:
SyntaxError: invalid syntax

1 Like

Hey, I think seeing all the code with correct intending would help quite a bit. I think this is likely a indentation or an issue with the else, if, and elif formatting.

I can confirm that the line that you’re getting the error on doesn’t seem to have a syntax issue. The error is likely in a line above that one.

The line after that; print “You guesses that one already”; does have a MINOR typo that won’t stop the program from running. Just need to change ‘guesses’ to ‘guessed’ and to close the sentence with a period. Might not be an issue, but sometimes the validation testing looks for EXACT printing text.


Yea, this is your issue right here, double check it.


LOL, I totally missed that!!! Kind of stands out when you look at just that one line!

Nah, it stands out when you become more familiar with the syntax. Try going back and forth between c++, c# or java back to python then you will have some issue.

Thank codyroche and zeziba. I applied your suggestions but still have the same issue :confused:/
Can anyone give me the code so maybe I can figure out.

Post what you have and let’s take a gander!

1 Like

I just sort out the problem. Thank you so much zeziba :slight_smile:

Can you please post your code because I am having the same trouble and ca’t seem to find the answer.

For the time being put the code that gives syntax error as a comment. Later it will be sort out by itself.

Hope this helps bud

if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"
    if guess_row not in range (5) or guess_col not in range(5):
        print "Oops, that's not even in the ocean."
    elif board[guess_row][guess_col] == "X":
        print "You guessed that one already."
        print "You missed my battleship!"
        board[guess_row][guess_col]= "X"
        print print_board(board)

so the point for me is that I should put elif below if statement and the last one is else…thanks