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


#1

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

Thanks!


#2

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?


#3

Added the link to the post check it out.


#4

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

this part:

    random_row(board)
    random_col(board)

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)

#5

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


#6

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


#7

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