Very confused with the code...
codecademy's code prints the "X" 1 spot higher in the column and row on the printed board and also allows the ship to be placed off the board, at [0,0] for example.
Problems with original code?
--without adding " + 1" outside the randint to the function the boat can be off the board and not include column and row 5 since the range would be 0 - 4; with the edit the range is 1 - 5
--range(5) doesnt take input of 5 as on the board unless changed to range(6)
--without the " - 1" to the else statement to place the "X" on the board; the "X" is printed 1 spot higher than the user inputs
I made the following changes outside of codecademy in python and it seemed to fix some but not others.
def random_row(board): return randint(0, len(board) - 1) + 1 def random_col(board): return randint(0, len(board) - 1) + 1 [...] else: if guess_row not in range(6) or guess_col not in range(6): print ("Oops, that's not even in the ocean.") print_board(board) else: print ("You missed my battleship!") board[guess_row - 1][guess_col - 1] = "X" print_board(board)
I'm not really sure if I made it redundant since codecademy is my only experience with python. Can someone with more experience confirm this error and fix or am I reading the code wrong?