Custom Print


#1

https://www.codecademy.com/courses/python-beginner-en-4XuFm/0/5?curriculum_id=4f89dab3d788890003000096#

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
print_board(board)

#2

What would the other version you mention look like?


#3

Here

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

#4

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


#5

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


#6

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


#7

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


#8

sure


#9

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


#10


#11

Please follow this:

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

#12

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