Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help pls (beginner)
#1
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 ?
Reply
#2
What have you tried?
Reply
#3
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
Reply
#4
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
Reply
#5
Hello,

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


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020