naraemee naraemee - 19 days ago 6
Python Question

How to make a board in python?

xxx
xxx
xxx


trying to find a way to make this 2D list.

Answer

One of the many ways to do it:

for x in range(row):
    print('x '*col)

For example, row =3, col =3 then output :

x x x 
x x x 
x x x 

Alternatively,

Create a list-

a=[]
for x in range(0, row):
    a.append(["x"] * col)

Then print it-

for row in a:
    print " ".join(row)
Comments