Class matrix novice question - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Class matrix novice question (/thread-2600.html) |
Class matrix novice question - John_paul - Mar-27-2017 Hello, Part of my homework: The attribute self.ground is the matrix who represents the ground of the game, it is a list of lists of integers, of dimensions self.height lines and self.width columns. The initial values are -2 in the first four lines and -1 on the rest of the ground. A negative value show that the case is empty I don't see at all what i must write. RE: Class matrix novice question - micseydel - Mar-27-2017 It doesn't look like you've provided enough information here. RE: Class matrix novice question - Ofnuts - Mar-27-2017 width=10 height=8 # You can create the lines like this # lineOfMinusTwo=[-2]*width # lineOfMinusOne=[-1]*width # So: ground=[] # Start with empty # lines of -2 for the first 4 for _ in range(4): ground.append([-2]*width) # lines of -1 for the rest for _ in range(4,height): ground.append([-1]*width) When you are a tattooed python programmer who wants to show off your one-liner mad skillz, the same thing can be done with: ground=[[[-1,-2][i<4]]*width for i in range(height)] RE: Class matrix novice question - John_paul - Mar-28-2017 Ok thank you. |