5/19 Custom Print Help!

board =
for i in range(0,5):
board.append([“0”] * 5)

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

print print_board(board)

The error is “It looks like you function didn’t print out the correct response!” but it looks fine:
[‘0’, ‘0’, ‘0’, ‘0’, ‘0’]
[‘0’, ‘0’, ‘0’, ‘0’, ‘0’]
[‘0’, ‘0’, ‘0’, ‘0’, ‘0’]
[‘0’, ‘0’, ‘0’, ‘0’, ‘0’]
[‘0’, ‘0’, ‘0’, ‘0’, ‘0’]

Change this to

print(' '.join(row}}

The only issue I see is that you’re printing your function instead of calling it!

Change from this:

print print_board(board)

to this:


1 Like

This is the correct code:

board = []

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

Hey @bytemaster89695,

You’re correct, however the issue is printing instead of calling the function. The code presented in this question is functionally the same as your example and will create the same output.

I agreed, but I don’t understand the difference between printing and calling.
what about return and calling also? I am confused. I have been google about this but still not clear. Please help

from my understanding: printing displays what you selected to print in the console window. Calling means to use and I am not to clear on return. It seems to mean what you want to pull from the function you created like if your function said a=1+5 and then you wrote return a it would pull 6.

I found this link on youtube. It might help clarifying print versus return https://www.youtube.com/watch?v=Mj0YwdiaViM I was totally wrong in the explanation of return.


print displays some output to the screen/console. print is a keyword.

message = "Test"
print message

This prints the word “Test” (without the quotation marks) to the screen or console.
###Call and Return

A function call is what makes the function’s code execute. In the code below, square(5) “calls” the square() function and sends along the integer 5 as a parameter that gets stored in the number variable as the function executes.

return is used in a function to finish/end the function and send a value back to wherever the function was called from.

def square(number):
	return number * number

print square(5)

So, to walk through this short code a little more slowly, here’s what happens. The code starts on line 1, which declares a new function. But nothing has told that function to run yet, so nothing happens.

On line 2, this is the inside of the function. But since the function hasn’t been called, nothing happens yet either.

On the third line of code (technically, line 4), we have a print command. But what will print? Well, it will print square(5). But that’s not a string or a variable. It’s a function call. So now we have to know what that function does.

So we move back up to line 1, and we bring the 5 with us, because it gets “passed” to the function.

We store 5 in the variable number and move on to line 2.

Now we see the return command. But what will the function return? It will return number * number. That’s 5 * 5 because the function call passed 5 in as the one parameter.

Okay, so the function returns 25. Where does it go?

It goes back to line 4 and gets sent to the print command. Now we know what we’ll print, which is the number 25.

So, in short, a call is a request to run/execute a function’s code. And a return is a command to return a certain value from a function to wherever the function was called from.

1 Like

I thought it’s supposed to be a capital ‘O’ instead of a ‘0’?
I had that problem too, but I tried using capital ‘O’ and it works. Try that.