I’m currently on step 13/19. I’m expected to write an elif statement asking to check if X is matching to the location of the guessed row and col. I’ve been given the clear up to this point, but the if statement doesn’t seem to make any sense to me.
if guess_row == ship_row: if guess_col == ship_col: print "Congratulations! You sank my battleship!" else: print "You missed my battleship!" board[guess_row][guess_col] = "X" print_board(board) if guess_row not in range(5) or guess_col not in range(5): print "Oops, that's not even in the ocean." else: print "You, missed my battleship!"
My understanding of the if logic is this…
if the condition is met, go inside and keep working. else, move on and do this.
So, the code, which has been cleared by the course, to me shows as this…
if the guess_row == ship_row go inside here and check if guess_col == ship_col, now go inside here and print “Congrats…”
Well, if the guess_row != ship_row, it should immediately return False and not move on.
My lesson is asking me to check if the guess_row and guess_col position in board contain the X string. The next lesson says it’s a fully functional version of Battleship for a single guess. The logic indicates otherwise. If that guess_row doesn’t match, the game should stop immediately.
What am I missing?