Learn
Battleship!
Bad Aim

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.

  1. They can enter a guess that’s off the board.
  2. They can guess a spot they’ve already guessed.
  3. 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 x or y are outside those ranges. The \ character just continues the if statement onto the next line.

Instructions

1.

Add a new if statement that is nested under the else.

Like the example above, it should check if guess_row is not in range(5) or guess_col is not in range(5).

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!

Folder Icon

Take this course for free

Already have an account?