# Not Again! 13/19

#1

Hey guys! Need help,I get this error
File "python", line 38
elif board[guess_row][guess_col] = 'X'
^
SyntaxError: invalid syntax

Also can someone explain this code : board[guess_row][guess_col] = 'X'
What does it actually do?

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)

print_board(board)

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

def random_col(board):
return randint(0, len(board) - 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!"
else:
print "You missed my battleship!"
board[guess_row][guess_col] = 'X'
if guess_row != range(5) or guess_col != range(5):
print "Oops, that's not even in the ocean."
else:
print  "You missed my battleship!"
elif board[guess_row][guess_col] = 'X':
print "You gussed that one already."``````

#2

`else` cannot precede `elif`, since it is the default case. Examine your conditional branching closely.

#3

File "python", line 31
elif board[guess_row][guess_col] = 'X':
^
SyntaxError: invalid syntax

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

#4

Your "elif" statement should look something like this, be sure to indent it equal to the "if" statement above it.

``elif(board[guess_row][guess_col] == "X"):``

Also the word guessed is misspelled on the line underneath.

#5

Thanks

elif(board[guess_row][guess_col] == "X"):

But can you explain about the parentheses () ?
I don't see it ever mentioned before in codecademy

#6

This does not work I still get
elif(board[guess_row][guess_col] == "X"):
^