This forum is now read-only. Please use our new forums at discuss.codecademy.com.

559 points
7c342a59f787ee9f6d70f1ef5d237b9f?s=140&d=retro
Submitted by
Zainab Ibrahim Djama
over 4 years ago

ex. 10/19 i can't figure out the problem. HELP!

from random import randint

board = []

for x in range(0, 5):
     board.append(["O"] * 5)

def print_board(board):
    for row in board:
        print " ".join(row)

print_board(board)

def random_row(board):
    return randint(0, len(board) - 1)

def random_col(board):
     return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

print ship_row
print ship_col

    if guess_row == ship_row and guess_col == ship_col:
        print "Congratulations! You sank my battelship!"

##Oops, try again. Did you remember your print statement that prints "Congratulations! You sank my battleship!" ? ##
i keep getting this error message but i tested it on my python idle and the code works fine. can anyone else see something am missing?


1 vote

permalink

Check the spelling of "Congratulations! You sank my battleship!" . There was were I had a mistake! :)

278 points
B97dd40dec2835ec5a6620be194f7ab5?s=140&d=retro
Submitted by
rugi.3b
over 4 years ago


0 votes

permalink

I got the same problem and I solved it moving print ship_row and print ship_col on line 23-24 respectively just below ship_col = random_col(board).. In this way I actually was able to 'guess' the correct row and the correct col and turn the if statement true...
hope this helps you

1273 points
54a6be529113cb99dd0031e5_913315478
Submitted by
Pito Fru
over 4 years ago

6 Comments

7c342a59f787ee9f6d70f1ef5d237b9f?s=140&d=retro Zainab Ibrahim Djama over 4 years ago

i tried your way but am still getting the same error message, i cant seem to get the if statement to be true. any more ideas

Bd98d45acd0a85cfd8ff509d8d6a624f?s=140&d=retro Volkan Gunduz over 4 years ago

Does it work if you move your if statement to the very left so that there is no indentation?

7c342a59f787ee9f6d70f1ef5d237b9f?s=140&d=retro Zainab Ibrahim Djama over 4 years ago

it's actually on the left, i think i might have accidentally indented it when i was posting the code here...

7c342a59f787ee9f6d70f1ef5d237b9f?s=140&d=retro Zainab Ibrahim Djama over 4 years ago

i was able to finish the entire coding for the battleship..the code work perfectly when i get through the last exercise...it just wont run on exercise 10/19

54a6be529113cb99dd0031e5_913315478 Pito Fru over 4 years ago

Did you try to refresh your browser?

7c342a59f787ee9f6d70f1ef5d237b9f?s=140&d=retro Zainab Ibrahim Djama over 4 years ago

tried but nor result..