master maste
New Member
- Reaction score
- 32
Ok, I'm trying to draw a game board in python, here is my current code:
but at the moment it prints out like this:
I want to have the 0's in their respective columns but can't for the life of me figure out/remember how to strip a list...
Heres the outcome I want:
+-+-+-+
| 0 0 0 |
| 0 0 0 |
| 0 0 0 |
| 0 0 0 |
| 0 0 0 |
+-+-+-+
0 1 2
(These should be lined up properly but the
Code:
def draw_board(n_rows, n_cols):
'''function to draw the board'''
n_cols = int(n_cols)
n_rows = int(n_rows)
matrix = [[0 for x in range(n_cols)] for y in range(n_rows)]
print matrix #for testing purposes
print "+-" *(n_cols) + "+"
for x in matrix:
print "|",
print x,
print "|"
print "+-" *(n_cols) + "+"
print "",
for x in xrange(n_cols):
print x,
draw_board(5, 3)
but at the moment it prints out like this:
Code:
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
+-+-+-+
| [0, 0, 0] |
| [0, 0, 0] |
| [0, 0, 0] |
| [0, 0, 0] |
| [0, 0, 0] |
+-+-+-+
0 1 2
Heres the outcome I want:
+-+-+-+
| 0 0 0 |
| 0 0 0 |
| 0 0 0 |
| 0 0 0 |
| 0 0 0 |
+-+-+-+
0 1 2
(These should be lined up properly but the
Code:
blocks refuse to do so, and so does the normal formatting, I'm sure you get the idea though :))
Would be awesome if anyone could give me a hint or something, I'm really lost for where to go next.
Thanks :eek: (long post)