Traceback (most recent call last): File "python", line 45, in <module> ExecTimeoutException: Program took too long to terminate

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

from random import randint

board =

for x in range(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)
print ship_row
print ship_col

Everything from here on should go in your for loop!

Be sure to indent four spaces!

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”

Print (turn + 1) here!


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


So… Here is my code and i’m trying to complete the battleship game exercise. I am on step 15/19 and I think I got it right. However, I am getting a strange error that I dont understand and I also dont understand why it is happening in the first place. Can anyone with more experience shed some light on the issue?

The error in question is this one:

“Traceback (most recent call last): File “python”, line 45, in <module> ExecTimeoutException: Program took too long to terminate.”


Ps: I tried searching for the answer before posting, just like the guidelines told me to, but to no avail. Sorry if this question has been asked multiple times before!

I have the same issue; my version of the battleship code works perfectly fine in eclipse and on my terminal. After trying to modify my code to avoid this error, I tried to use Codecademy’s own “Solution” code. That too, throws this error every time I run it. Unfortunately, my only solution now is to test my code independently to see if it works, and then have to make deliberate error on the Codecademy prompt, so that I can use the suggested solution to move ahead. If not, there is no way for me to see what next part of the assignment is, even though my code actually works!

I did notice that even if you guess correctly, it would continue to ask you for another row input. I got the timeout exception error if I did not enter inputs for all of the turns.

Eventually it stopped giving me the error if I entered guesses for every turn (even if I guessed it correctly previously)