Not Again! (Syntax Error)


#1



https://www.codecademy.com/courses/python-beginner-en-4XuFm/1/4?curriculum_id=4f89dab3d788890003000096#


Everything I have entered should be correct, I've visited other people's code that is almost identical to mine and they have no errors when running it.
The exact error is:

elif board[guess_row][guess_col] == "X":
^
SyntaxError: invalid syntax


I don't understand this error.


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


#2

elif ____: may not follow else:


#4

Ok, should I remove the else: and change the elif: to if:?


#5

Place all the code before the else so that it is the last case in the conditional branch.

if ___:

elif ___:

else:

#6

Okay, that makes much more sense. Sorry for the confusion!


#7

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