# Unexpected output

#1

Hello

For the 13. Not Again! exercise in Battleship! with the following 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[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!")
elif board[ship_row][ship_col] == "X":
elif guess_row != range(5) or guess_col != 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)``````

I am getting the following output:

``````O O O O O
O O O O O
O O O O O
O O O O O
O O O O O
Guess Row: 3
Guess Col: 2
4
0
Oops, that's not even in the ocean.
None``````

I can't figure out why the 2nd elif condition is being triggered instead of the else condition

#2

well, `range()` produces a list as output, guess_row is an integer. an integer doesn't equal a list, so the condition is true, so the code prints that the guess is not in the ocean

#3

Thanks a lot stetim !

And I also wasn't using "not in" boolean expression... So it wouldn't have worked either way.. I need to start reading things closer

#4

that was my point exactly, `!=` won't work, like you discovered you need to use `not in`

#5