Hide... I think they hid the answer


#1

I can't seem to get past this point. I've even started over again, to make sure I wasn't missing a space somewhere. Help?

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)

def random_row(board):
    randint(5, len(board) -1
    
def random_col(board): # <--SyntaxError: Invalid syntax
    randint(5, len(board) -1
    
return random_row(board)
return random_col(board)


#2

You are missing a ) to close the statement. Each start needs a stop. If you have any more issues ask again and I will try to help you.


#3

I realized that seconds after posting. However, fixing that I have a new error. I now get: Oops, try again. It looks like your row bounds are not correct.

Code as follows now:

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)

def random_row(board):
    randint(5, len(board)) -1
    
def random_col(board):
    randint(5, len(board)) -1
    
random_col(board)
random_row(board)

#4

Put that by it's self and replace the len(board) with any number. You should quickly see your problem.

If you don't, you should know when you give randint a range of numbers it goes from left to right

randint(0,5)
# Returns a number 0-5

Anything else?


#5

I finally got it. Thank you!

Although, interestingly enough the first time I ran the code it told me my numbers weren't random enough, to run again. When I did, it gave me the pass. Is there a reason for this?

The code that worked for me:

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)

def random_row(board):
    return randint(0, len(board) -1)
    
def random_col(board):
    return randint(0, len(board) -1)
    
random_col(board)
random_row(board)

#6

@aleafonthewind

The checker can get confused easily, not much of a reason though.