Python Forum

Full Version: Help pls (beginner)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I would like to create a game board, with is something like that :

x x x x
x x x x
.  .  .  .
.  .  .  .
o o o o
o o o o

I would like to create this :
A « newBoard(n,p) » function where n and p are positive integers, with n > 4. It returns a two dimensions list that represent the initial state of a board composed of n rows and p columns.
The board will naturally be a two-dimensional list of integers equal to 0, 1 or 2. An empty square will be represented by a 0, a pawn of the first player by a 1 and a pawn of the second player by a 2.

I don't know how to create this type of grid like for example, if I enter n=8, p=3 i want this:
x x x
x x x
. . .
. . .
. . .
. . .
o o o
o o o
can some1 help me plz ?
What have you tried?
I tried this :
def newboard(n = 5, p = 4) :
if n > 4 :
print ([['x']*n for x in range(n)])
newboard()

but that not work (i am a total begginer) do not find how to create a board or grid on the net

pls help me
Can you be more specific than "not work"?

What do you mean, "total beginner", did you not get instructions before this homework?

Yes, there is probably no explanation for the complete solution on the net. You need to split your big problem into smaller problems, then solve the smaller problems one by one
Hello,

Take a look at my response in http://python-forum.io/Thread-Input-Replacement