Gameboard assignment

Im just a newbie, pls. help, the code below is already running fine, but i need to return True once the function is done. Where should I insert from my code? Thanks in advance

def GameBoard(row, column):
for row in range(row, column):
if row % 2 == 0:
print(" | | “)
else:
print(”------")

row = 0
column = 5
GameBoard(row, column)

Why don’t you try putting return True in different places in the
function and see what it does? Your function only has five lines (not
including the def ... line) so there are less than ten places you can
insert a return line. (Actually eight, if I am counting correctly.)

Experiment. Save your file and run it. See what it does. Now put a
return True in the function and run it again. See if you can
predict what will change, and see if your prediction is correct.

def GameBoard(row, column):
    return True  # what will this do?
    for row in range(row, column):
        if row % 2 == 0:
            print(" |  | ")
        else:
            print("------")

Then move the return line to a different place and do it again. If you
get a SyntaxError, don’t worry – just change the position and try
again.

Remember that when experimenting, it pays to keep a backup copy of your
file from before the experiment started.

Don’t forget that indentation matters to Python. These two versions are
different:

# Version 1
def GameBoard(row, column):
    for row in range(row, column):
        if row % 2 == 0:
            print(" |  | ")
        else:
            print("------")
        return True  # indented *inside* the loop


def GameBoard(row, column):
    for row in range(row, column):
        if row % 2 == 0:
            print(" |  | ")
        else:
            print("------")
    return True  # indented *outside* the loop

Hi Steven,

Thanks for your advise, below is what I did

def GameBoard(row, column):
for row in range(row, column):
if row % 2 == 0:
print(" | | “)
else:
print(”------")
return True <== i add it in here

print(GameBoard(0, 5))

Output:


| |
True