Help on 11/13


This is my code:

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)


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

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

shiprow = random_row(board)
shipcol = random_col(board)
guessrow = int(raw_input("Guess Row:"))
guesscol = int(raw_input("Guess Col:"))

print shiprow
print shipcol

#Write your code below!
if (shiprow == guessrow) and (shipcol == guesscol):
        print "Congratulations! You sank my battleship!"
        print 'You missed my battleship!'
        board[guessrow][guesscol] = "X"

I get this error -
Traceback (most recent call last):
File "python", line 33, in
IndexError: list index out of range
Can someone help please?????


Only input numbers in the range 0-4 (inclusive) This problem for failing with invalid numbers is fixed in the next exercise -


when you guess, keep it in the range for column and row. If you put the user input outside the row or col, it will give you and error. do user input 4 and 0..


The last print statement -- print_board(board) -- should be in the separate line not in the --else-- case.


@bin123 no this is not the OP's problem.