5/19, question regarding instructions?


#1

Based off of the instructions for 5/19, here is the function I have defined (along with calling the function at the end and the preceding code from the previous exercises):

 

for i in range(5):
  board.append(["O"] * 5)

def print_board(board_in):
  for row in board:
    print row
    
print_board(board)

 

It passed. Now I’m wondering why the function it isn’t supposed to be:

 

  for row in board_in:
    print row
    
print_board(board)

 

I thought that ‘for’ statements within functions should be calling the same name of the argument you provided when defining the function (in this case, ‘for row in board_in’ instead of ‘for row in board’)?


#2

It should be, to be self-contained. board is a global, outside of the function, still accessible, but more appropriately it would be accessed through the parameter variable which is a stand-in name for the function to use locally.


#3

Hi @newlearner90210,

Yeah, the instructions do indeed include this …

Inside the function, write a for loop to iterates through each row in board and print it to the screen.

Good call on your part. The instructions got it wrong, and should be revised. Codecademy staff, please take note.


#4

Thank you! I just wanted to make sure that I was correctly applying what I have been learning so far. It seemed a little off to me so I wanted to make sure my suspicions were correct.


#5

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