# 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)

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)
print ship_row
print ship_col

# 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!”
else:
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.”
else:
print “You missed my battleship!”
board[guess_row][guess_col] = “X”

# Print (turn + 1) here!

print_board(board)

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.”

Thanks!

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!

1 Like

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!

1 Like

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)

It’s not your code that’s faulty. Including parentheses with the print statement appears to resolve the issue.

If you type the previous print lines like this, it doesn’t give the problem:

``````hip_row = random_row(board)
ship_col = random_col(board)
print(ship_row)
print(ship_col)

guess_row = int(raw_input("Guess Row: "))
guess_col = int(raw_input("Guess Col: "))

# Write your code below!
if guess_row == ship_row and guess_col == ship_col:
print("Congratulations! You sank my battleship!")
``````

This may be a Python version mismatch issue.

Yes. The Battleship project is part of the Python 2 course, so writing `print "This is a string"` is the correct syntax for Python 2.

I had the same problem:
Traceback (most recent call last): File “python”, line 28, in ExecTimeoutException: Program took too long to terminate.
From what i figured out - it prints the error when i run my final code and wait too long between each guess (or between starting the game and finishing it). how is it possible to give the person guessing more time?
p.s. i didn’t add my code since this is the only problem, the rest of my code works perfect