7. Hide


#1

Task

Define two new functions, random_row and random_col, that each take board as input.
These functions should return a random row index and a random column index from your board, respectively. Use randint(0, len(board) - 1).
Call each function on board.

My 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)

# Add your code below!
def random_row(board):
    randint(0, len(board) - 1)
    

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

print(random_row(board))
print(random_col(board))

Error:
Oops, try again. It looks like your row bounds are not correct.

What the f**k is wrong with me or site or python or whatever? why i every time do exactly as saying in task and get piece of s**t in my face?


#2

Instructions says:

Yet you are not returning anything.
If you are getting frustrated, rest a bit/take a break. Else, read instructions a bit more carefully :slight_smile:


#3

Thank You, I really appreciate that.

Right 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)

# Add your code below!
def random_row(board):
    return randint(0, len(board) - 1)
   
    
def random_col(board):
    return randint(0, len(board) - 1)
    


print(random_row(board))
print(random_col(board))

Changed only random_row and random_col filler, exactly i just print "return".


#4

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