Custom Print


Why does the instructions ask us to create a function to print the board list when we can just use print function like print board[i] . It gives the same output.

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


What would the other version you mention look like?



for i in range(0,5):
    print board[i]


Would you only print the board after having created it? One would probably want to print the board after having taken a couple of shots at it

And if you're printing it at multiple places in your code, then you'll 1) save yourself a couple of lines and 2) only have to change the printing in one place if you decide it should be presented some other way


Im sorry i didnt get you. Im new to programming!


Your alternative appears to be to only print it immediately after (during even) creating the board

One would also want to display the board after having changed the state of the game


I see but i can do the same without a specific funtion for printing,right?
Like I will print my board after i complete making necessary changes




So my question is what is the advantage of creating a function rather than just printing?



Please follow this:

  1. Use a for loop to append "O"
  2. Use another for loop to print values (do not make it nested)


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