I have the proper code but the window shows broken grid


#1



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


Everything in my code is correct and codeacademy accepts my code but the grid pattern i'm getting looks like this
[['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'], ['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']]
[['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']]


HELP! lol


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


#2

because you put print board inside the loop, you see the build up of the board

each iteration of the loop, a row is added to your board, so the first line displays the first row, then you add another row and print the board again and so on, you witness the build of your board

if you want only to print the board after its completely build, place print board outside the loop


#3

ahh i see it now. Stupid mistake! thank you!


#4

sorry for the double post. I pulled the print board out and re ran my code but still haven't been able to get the nice grid pattern every body is getting.

"""
board = []
for i in range(5):
___board.append(["O"] * 5)
print board
___ denotes tab
"""

Result
[['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']]


#5

this is building your board, you printing your board and printing it pretty in the next few exercises

how the data is useful for us programmers (list) and how we represent the data to the user (fancy) often doesn't match


#6

yup i see it now putting the horse in front of the wagon again lol Thanks for your help!


#7

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