Why? 6. Printing Pretty


#1



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


Code is working fine. I solved the exercise but I wanted to test something, it didn't work and here I am to ask why.

So, why can't I do this?:

" ".join(board[item])

Interestingly enough, if I code this: print " ".join(board[item]) it does let me pass even though it doesn't change the format.

If I take out the print item from print_board it does let me pass but it presents two formats, one correct and one wrong.


def board():
    board = []
    for item in range(5):
        board.append(["O"] * 5)
        " ".join(board[item])
    return board
    
def print_board(board):
    for item in board:
        print item

print_board(board())


#2

syntax wise you can do this, but why would you? You join a list into a string, to then do nothing with it?

this does change the format. Now you clearly should see the nice representation of the board:

O O O O O
O O O O O
O O O O O
O O O O O
O O O O O

this code:

print_board(board())

doesn't make much sense, you are going to construct a new board every time you want to print the board?


#3

Oh, you're correct, I'm too dumb. I just needed to do away with the second function and it works fine now.

When I started programming I never thought that I would trip up so much on these little attention details.

Thanks for helping me.


#4

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