5/19


#1

well hi gentlemen and ladies, or hi everyone
hi, I really need help with this question
board = []
for i in range(0,5):
board.append(['O' * 5])

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

print_board(board)

this is what I have and it is not working plz help


#2

Hey 13ajiths,

I'm thinking you've got an issue with the output. Your output looks like this:

['OOOOO']
['OOOOO']
['OOOOO']
['OOOOO']
['OOOOO']
None

The configuration for this project is looking for output 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']
None

The reason for this difference is a slight tweak to your .append. It should look more like this:

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

The reason this is important is that your code is creating 5 items in the board[]:

board[['OOOOO'],['OOOOO'],['OOOOO'],['OOOOO'],['OOOOO']]

This would cause issue when you need to refer to rows and columns later, as you've only got 5 elements.

The board list would need to allow reference down to each item, so it should be stored like this:

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"]]

Hope that helps!


#3

@codyroche

Actually it is simpler than that. Just do,

def print(board(board):
    for row in board:
        print(' '.join(row))

Unless you use the string method join you will not get nice print outs and will just get what the computer is storing in the data banks.

EDIT:

I didn't see his goofy code for the board generator ether good to point that out!


#4

Funny, and I didn't look further for the second issue you'd pointed out! That's the fun with a forum to discuss this stuff.


#5

I use the forum for the simple purpose of improving my skills. It is an added bonus to get to help others though. I have surpassed most of the issues that people on here can come up with so I have moved on to some more interesting things.

You want some interesting problems look here, not only will it challenge your programming abilities but your knowledge of math and the theories that it includes. You can google most of the math stuff to figure out how to do it but implementing the code is the important part.

As always best of luck!


#6

That's an interesting challenge! I'll have to test writing the code for some of those later.


#7

I have the same code as you except i have double quotes instead of ingle in the append statement. No idea if that makes a difference or not as they seem to be used interchangeably. Here is my code and the output it returned:

board = []
for x in range(0,5):
    circles = ["O"]*5
    board.append(circles)
def print_board(board):
    for row in board:
        print row
print_board(board)

here is the output:

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


#8

Double and single quotes are MOSTLY interchangeable. If you Google it you can find some situations that matter, but for everything we're doing so far they are the same.


#9

Hi codyroche, Thank You.