I've gotten the code right but still get and error in the console


I am just a little confused on why this is still giving me an error even though I have gotten the code right and passed the lesson. Can someone please explain this to me?
link to exercise

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)
# Add your code below!
def random_row(board):
    randrow = randint(0, len(board) - 1)
def random_col(board):
    randcol = randint(0, len(board) - 1)
print randrow
print randcol



You're telling python to print a variable that is not defined globally.

Notice the indentation

Actually, on second thought, Would you mind posting a link to the exact exercise you are on?


Added the link to the post check it out.


Alright, just as I thought, the problem is right here:

this part:


should be outside the function.

Also, instead of using randcol and randrow to store randint values, just return them inside the function like this:

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


thanks for the help. gonna go back and edit my code to make it cleaner.


No problem, if you have any further issues with this exercise please just let me know.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.