Not Again! Invalid Syntax error


I am having trouble with my code because it isn't telling me what is wrong with my code:

from random import randint

board = []

for x in range(0, 5):
board.append(["O"] * 5)

def print_board(board):
for row in board:
print " ".join(row)


def random_row(board):
return randint(0, len(board) - 1)

def random_col(board):
return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

print ship_row
print ship_col

if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sank my battleship!"
print "You missed 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."
print "You missed my battleship!"
board[guess_row][guess_col] = "X"
elif guess_row or guess_col == "X":
print "You guessed that one already."



Don't put another elif after else (else is always last) change the place of those two and that should do it :slightly_smiling:


Hello caleam,

First of all, you simply copy/paste your code and indentations couldn't be understandable. So edit your message above with backsticks.Backsticks key location differ on your keyboard which your original language is. Also you can do it with your message screen on this menu with </> . Select all of your code then click </> button or use backsticks. Google it "Backsticks" if I can't make myself clear.


Regarding this exercise, i think i missed something.

We are asked to check if a previous entry matches our current entry.

But how can we check our previous entry if there is no previous one,
the exercise does not mention how to enter the second guess.

I would excpect a condition to be met and untill then you need to keep entering guesses.
like you only get 3 guesses or so.


You could ask for the input in a for-loop, and make the user guess until the chances to guess are 0 or he destroyed all ships ^^

I think this exercise is also kind of a challenge, where you have to use the knowledge from the exercises before to make this game :slightly_smiling:


I do not mind it being a challenge, but given that the syntax is checked pretty strict.
(some exercises didn't pass until i ordered my code better)

but indeed if they would just mention you could/should use the for loop or whatever to accept input
it would have helped.


There is no for loop needed for this exercise until you get to step 15. And then it does mention you should use the for loop. Until then, none is needed. But you never said which step you're on.

If you're still having difficulty, please paste the error message and the step you're on, along with your current code.