Understanding "HIDE..."


i cant understand the question , also if the board is always square (same number of colums and rows), why do we need 2 functions instead of 1 , they look just the same.

Replace this line with your 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 rand_col(board):
    return randint(0,len(board)-1)    
#bdw , also tried this : 
def rand_col(board):
    lst = board[0]
    return randint(0,len(lst) -1)    


By having two functions we leave the option open for a non-square board. If there is no desire or possibility for the board to not be square, then yes, a single function is adequate enough to fill all needs.

There would be one adjustment required to maintain independence of axes...

def rand_col(board):
    return randint(0,len(board[0]) - 1)

This will give us the number of columns, independent of the number of rows. This was not introduced in the course, but arose in the forums many years ago and has since been copied countless times. I am happy to see that you are following the instructions and not searching for solutions.

There is a topic (a few actually) in the Corner Bar on this project. Here is some code that can be used as square or non-square depending how it is set up...


However, let's not bring that into this discussion and stay the course of instructions. You may join any conversation in the Corner Bar to take up the more advanced ideas.


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