Play it, Sam


This is my code below. It prints to the console just like expected, but I'm still getting the error saying I didn't print turn + 1. Any thoughts would be great.

board = []
turn = 0

for turn in range(4):
    print "Turn", turn + 1
    guess_row = int(raw_input("Guess Row:"))
    guess_col = int(raw_input("Guess Col:"))

    if guess_row == ship_row and guess_col == ship_col:
        print "Congratulations! You sunk my battleship!"
        if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
            print "Oops, that's not even in the ocean."
        elif(board[guess_row][guess_col] == "X"):
            print "You guessed that one already."
            print "You missed my battleship!"
            board[guess_row][guess_col] = "X"


refresh the page !!
your code works for me


try to play the game and keep guessing four times and it will work


@azazaz, sycamore_brad's code allow for the lesson to be but the code is not good for an actual game of battleship. The For loop that sycamore_brad wrote is good for looking, but it does not go through the IF conditions (that we added in previously) until the very last attempt. For example, you can enter (0,1) three time and it will not print the "Oops...." message nor will it print that you guessed a coordinate outside of the range if you were to enter (7, 10384) unless it was during the very last attempt. Additionally, the game will not print out the board until the last guess (the game should print out the board after each guess entered into the complier).

@sycamore_brad try moving your For loop to a different part of the code and make sure that the necessary code is inside of the For loop after you move your loop.