Great job! Now we can handle both correct and incorrect guesses from the user. But now let’s think a little bit more about the “miss” condition.
- They can enter a guess that’s off the board.
- They can guess a spot they’ve already guessed.
- They can just miss the ship.
We’ll add these tests inside our
else condition. Let’s build the first case now!
if x not in range(8) or \ y not in range(3): print "Outside the range"
The example above checks if either
y are outside those ranges. The
\ character just continues the
if statement onto the next line.
Add a new
if statement that is nested under the
Like the example above, it should check if
guess_row is not in
guess_col is not in
If that is the case, print out
"Oops, that's not even in the ocean."
After your new
if statement, add an
else that contains your existing handler for an incorrect guess. Don’t forget to indent the code!