Why does it ask if I’ve created the random_row or random_col function?
Answer
If you’ve misspelled the name of the randint() function that we use to generate a random number, that will cause this error because Codecademy is testing the return value from your function.
Another common issue is not returning the random value you generate, so be sure to do that!
def random_row(parameter_name):
# return random value here
Is it okay to have the argument in a function as the same name as the variable named above? It just seems a bit strange to do this since it is normally different:
board = []
for x in range(0, 5):
board.append(["O"] * 5)
def print_board(board):
for row in board:
print " ".join(row)
It is okay, as you are merely naming an argument for that function.
However to make the code less confusing, you may want to make the name of the argument different from the name of the variable board that you have created already.
Hey
I understand the rational behind the first parts of: randint(0, len(board_in) - 1), up until the (board_in) section. However, I am a little confused by the reasoning behind the: " - 1 " being added at the end.
Could someone please elaborate on that “- 1”?
length starts counting at one, while indexes start counting at zero. If we don’t compensate for this, we could generate an index which is out of bounds.
both random_row AND random_col retunrs random int in range of size of ROW. Trying to make rectangle like 10x2 will probably result with random_col out of range.
Can someone get a code how to get sieze of the list in list (this is what a bord is; 5 list and 5 string in every of those 5 list)