If the input to the battleship game is a non-integer value, you get the error:
Traceback (most recent call last):
File "python", line 31, in
ValueError: invalid literal for int() with base 10: 'l'
The input from the raw_input() function is always taken to be a string, so we use the int() function to convert it to an integer. That's what gives the error when trying to convert a letter into an integer, for example. I'm wondering if there is any way to check the input and provide a message to the effect of "Please enter a valid integer" if the input is in fact a non-integer, before attempting to convert the input to an integer with int() and getting the console error.
Here is the code of interest:
for turn in range(4): print "Turn", turn + 1 guess_row = int(raw_input("Guess Row:")) - 1 guess_col = int(raw_input("Guess Col:")) - 1 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: board[guess_row][guess_col] = "X" print_board(board) print "You missed my battleship!" if turn == 3: print "Game Over"