7/13: Unknown Syntax Error


#1

ok so I have this code:

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(x):
    from random import randint
    return randint(0, len(x) - 1)

def random_col(x):
    from random import randint
    return randint(0, len(x[0] - 1)

random_row(board)
random_col(board)

but I get an error from the console

  File "python", line 22
random_row(board)
         ^
SyntaxError: invalid syntax

and I don't know the problem with my syntax. Help please?


#2
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(x):
    return randint(0, len(x) - 1)

def random_col(x):
    return randint(0, len(x) - 1)
    
x1 = random_row(board)
x2 = random_col(board)

This should work . And you don't need to import randint from random module everytime , once you import it at beginning it is fine.