3/19 Make a list and 4/19 Check it twice


#1

Here's my code and I got an "Oops, try again. It looks like the rows are not represented as lists," I must figure this out?

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

Second try got same "Oops, try again. It looks like the rows are not represented as lists.":

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

Third try it passed but is this correct?

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

Printed to console:

0
1
2
3
4
None

Here's another one that will pass but I'm not sure if this is how it's suppose to look?

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

It prints this to console:

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

Here's another and I think this one is the correct one?

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

It prints:

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

I've been messing around with this and I have got it to appear in top, middle, bottom of the console screen. I really don't know which one is right but moving on anyway.


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

Is alright, but in this lesson you don't need to print anything.
My code is:

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

If you want to print out the board, do it outside of the loop, otherwise you print it out too often, and before it is complete.


#3

Yeah I'm on 4/19(It tells you "Use the print command to display the contents of the board list.")and moving on like I said, wish I knew which one was correct?

I guess that question is irrelevant since 5/19 tells you to use a for loop to place on a different line. LOL WOW!


#4

thanks eveat...:grin: ..good and simple code


#5

good post, I was stuck by this section.

I originally think just repeat 5 "O" in board, but that's wrong, board is a list which it have 5 sublist that have 5 "O"

so , the right code is :

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


#6
board=[]

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

#7

I believe I have missed a lot of content codeacademy had to offer due to the fact I wasn't running the issues in a seperate interpreter. In this case I use a text editor and save it in the folder where my powershell opens(using windows 7) and run it from there. Please let me know if there is a faster way to run it. Personally I need the extra visualization to wrap my head around it. Thanks for all your support in the forums.


#8

The lines below help with visualizing the board.

for row in board:
print row

The 'print row' line is suppose to be indented.... Can't get it to show as indented on this thread...


#9

If you installed python on your PC, you should already have the IDLE IDE.

Right click on a .py file and selecet "Edit with IDLE". Inside IDLE you can run a saved program by pressing F5 or using the menu at the top.

I hope this is what you are looking for.


#10

I got a question, if the range(stop) function does not include the stop, why do we type range(5) if we want to generate 5 grids?
it's correct i just don't understand why


#11

range(5) returns a list with 5 numbers. 5 is not included but 0 is.


#12

If have a question about the for loop. You define:
for i in range(5)

however, there is no i in:
board.append("O" * 5)

Can someone explain to me what Python does here exactly? Thanks!


#13

Here is the right code:

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