If I input my code as is, when it prints the board after my guess, the 'X' is in the wrong coordinate position than someone would expect if they were playing, giving (x+1,y+1) .
Yet, if I modify the line:
board[guess_row][guess_col] = 'X'
board[guess_row - 1][guess_col -1] = 'X'
it gives me the correct output on the board when it is printed after the guess, but tells me
> "Oops, try again. You're updating 'guess_row - 1' and 'guess_col - 1' instead of 'guess_row' and 'guess_col'."
I know that the random ship is placed according to it's index position in the row, but I'm trying to work on the assumption that whoever is going to play would use the coordinates (1-5) rather than the index position (0-4) because common sense. I believe i want to change the result of guess_row so that it is -1 whatever the raw input is, but I don't know how, and I also believe this would mean that the line
if guess_row == ship_row and guess_col == ship_col
would mean that even if the position on the printed board was correct, the code would mean that the 2 aren't aligned properly so would return a miss?
I hope i've explained this well enough for someone to offer their help! The code that i have that it tells me is correct is:
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) print_board(board) def random_row(board): return randint(0, len(board) - 1) def random_col(board): return randint(0, len(board) - 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:")) if guess_row == ship_row and guess_col == ship_col: print "Congratulations! You sank my battleship!" else: print "You missed my battleship!" board[guess_row][guess_col] = 'X' print_board(board)