tl;dr What is the "-1" and the "" for in randint(0, len(board) - 1) and range(0, len(board) - 1), I'm so confused on this?
So here's the code I use in 13/19:
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:")) # Write your code below! if guess_row == ship_row and guess_col == ship_col: print "Congratulations! You sank my battleship!" else: if guess_row not in range(0, len(board)-1) or \ guess_col not in range(0, len(board)-1): 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_board(board)
The hint in 12/19 says:
The valid values for guess_row are 0 to rows-1 and the valid values for guess col are 0 to cols-1. You will need to build up a complex Boolean expression of the form:
The instructions say to use: range(5)
Now in 13/19 I use the:
guess_row not in range(0, len(board)-1) or \ guess_col not in range(0, len(board)-1)
and it messes the results up telling me "Oops, that's not even in the ocean." When I use 4 for column and 4 for row.
I then delete -1 for both and it's ok to run it through and it works? I'm not understanding that piece of code why we use it in the random functions(randint) but it doesn't work in the if statement (range)?