# Where did I mess up? 13/19 Not Again!

#1

My sloppy code is probably making this way harder than it needs to be. Here's everything, I think the bad code is making 13/19 difficult.

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

Where have I gone wrong?

#2

take a look at your elif line...you should think about that just like when you assign a value to a matrix coordinate.
So you will have:
`board[guess_row][guess_col] == "X"`

#3

Never mind, I figured it out!

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

It was just, strangely, in the wrong way. Bah myself.

#4

this is what i did and it worked.

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

#5