12. Bad Aim keeps getting an error


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[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

Write your code below!

if guess_row == ship_row and guess_col == ship_col:
print ("Congratulations! You sank my battleship!")
if guess_row > range(5) and guess_col > range(5):
print "Oops, that's not even in the ocean."
print ("You missed my battleship!")
board[guess_row][guess_col] = "X"

Traceback (most recent call last):
File "python", line 36, in
IndexError: list index out of range


This is just a part of a code. Paste your whole code with indents. To do so paste it between three backqoutes/backticks before your code and three backquote/backticks after your code.


okay i updated it to a full one


Okay, however still there are no indents.
Copy your code form codecademy course, put three backqoutes

Paste your code and again put three backquotes. It probably won't work on already pasted code, that's why I advise you to copy it again.

Also please tell us what error do you get.


this is the error.

Traceback (most recent call last):
File "python", line 36, in
IndexError: list index out of range

i placed indents for the if statements etc but the preview over here just moves all the code to the start of the line


Well, let's try with what we have.
I am guessing this is lesson 12. Bad Aim.
Check instructions again, cause it clearsly tells you what you should use to determine if guess is or is not in range. Definitely you shouldn't use ">"

About indentation, do not edit code after you paste it to the message box. You can try also something like that. Copy code , paste it, select it and use Ctrl + Shift + C