Battleship - observation

#1

I noticed when I played battleship, the following -
Let's play Battleship!
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: 5
Guess Col: 5
Oops, that's not even in the ocean.
Turn 1
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: 5
Guess Col: 5
Oops, that's not even in the ocean.
Turn 2
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: 5
Guess Col: 5
Oops, that's not even in the ocean.
Turn 3
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: 5
Guess Col: 5
Oops, that's not even in the ocean.
Turn 4
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
None
I was wondering why does it not say in turn 2 - "You guessed that one already."?

Here is my codes regarding the two scenarios -

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

Thanks.

#2

Because it checks to see if it's in the ocean first. If it is not in the range that you gave it, the rest of the if statement will never run, and you will not see "You guessed that already"

#3

Thank you. I appreciate the fast reply.

#4

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