7. Hide

Can anyone help me? i keep getting the message: Oops, try again. Did you create a function called random_row?
My code is as follows:

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!

from random import randint

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

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

random_row(board)
random_col(board)

1 Like

Can you add triple backticks around your code, so it’s formatted with the tabs and everything?

^Those are backticks.
Add them before your code.
Then add three more after your code.

1 Like

Couldn’t be bothered, @james.rhea. Replies are not deserved.

1 Like

Its not that i couldnt be bothered, I tried but i didnt get the desired outcome… Why do you think i deleted my previous post?

You gave up too soon. Keep trying until you succeed.

 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!
from random import randint 

def random_row(board):
    return radint(0, len(board) - 1)
    random_row(board)
    
def random_col(board):
    return radint(0, len(board[0]) - 1)
    random_col(board)

Thank you. I was putting the backticks at the end of my code which is why it wasnt working.

@mtf Still here thank you.

Have you discovered that the two function calls belong outside of the functions, in global scope?

1 Like

I have & I tried putting the two calls in global scope as follows:

random_col(board)
random_row(board)

but i get the same message

Leave them where they are in global scope, and be sure they are removed from previous. Please let us see your new code (in a new reply). Thank you…

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):
    return radint(0, len(board) - 1)

    
def random_col(board):
    return radint(0, len(board[0]) - 1)
    
   
random_row(board)
random_col(board)
 

To what are you assigning the return values from the functions?

We assign the return values to ship_row & col_row but we only do that in the exercise after. In this one, they ask us to just call each function on board

Are we good then with the general error correction so we know you have moved on?

The obvious that escapes us all. It happens.

2 Likes

Wow can’t believe it… Thanks so much for the help
Will definitely double check everything before asking for help next time

Never be afraid to ask for help, especially given the path upon which you are embarking.