
from pixel import Pixel


class Pixelmap:

    def __init__(self, width, height):
        """Pixelmap constructor

        :param width: Width of map in pixels.
        :param height: Height of map in pixels.
        """
        self.width = width
        self.height = height
        self.map_matrix = [[0]*self.width for _ in range(self.height)]
        for row in range(self.height):
            for col in range(self.width):
                self.map_matrix[row][col] = Pixel()

    def __str__(self):
        """Human readable pixelmap description.
        Pretty much just the matrix.

        :return: Description of pixelmap.
        """
        return str('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in self.map_matrix]))

    def __repr__(self):
        """Internal representation

        Just use str for now.
        """
        return self.__str__()


from .pixel import Pixel


class Pixelmap:

    def __init__(self, cols, rows, default_val=None):
        """Pixelmap constructor

        :param cols: Width of map in pixels.
        :param rows: Height of map in pixels.
        :param default_val: Default value for pixels.
        """
        assert cols >= 0, 'Invalid Pixelmap width'
        assert rows >= 0, 'Invalid Pixelmap height'
        self.cols = cols
        self.rows = rows
        self.map_matrix = [[0]*self.cols for _ in range(self.rows)]
        for row in range(self.rows):
            for col in range(self.cols):
                self.map_matrix[row][col] = Pixel(default_val)

    def num_cols(self):
        return self.cols

    def num_rows(self):
        return self.rows

    def __str__(self):
        """Human readable pixelmap description.
        Pretty much just the matrix.

        :return: Description of pixelmap.
        """
        return str('\n'.join([''.join(['{:6}'.format(str(item)) for item in row]) for row in self.map_matrix]))

Add default value for matrix and methods to get columns and rows.
Add default value for matrix and methods to get columns and rows.

  
- from pixel import Pixel
+ from .pixel import Pixel
  
  
  class Pixelmap:
  
-     def __init__(self, width, height):
+     def __init__(self, cols, rows, default_val=None):
          """Pixelmap constructor
  
-         :param width: Width of map in pixels.
+         :param cols: Width of map in pixels.
-         :param height: Height of map in pixels.
+         :param rows: Height of map in pixels.
+         :param default_val: Default value for pixels.
          """
-         self.width = width
-         self.height = height
+         assert cols >= 0, 'Invalid Pixelmap width'
+         assert rows >= 0, 'Invalid Pixelmap height'
+         self.cols = cols
+         self.rows = rows
-         self.map_matrix = [[0]*self.width for _ in range(self.height)]
+         self.map_matrix = [[0]*self.cols for _ in range(self.rows)]
-         for row in range(self.height):
+         for row in range(self.rows):
-             for col in range(self.width):
+             for col in range(self.cols):
-                 self.map_matrix[row][col] = Pixel()
+                 self.map_matrix[row][col] = Pixel(default_val)
+ 
+     def num_cols(self):
+         return self.cols
+ 
+     def num_rows(self):
+         return self.rows
  
      def __str__(self):
          """Human readable pixelmap description.
          Pretty much just the matrix.
  
          :return: Description of pixelmap.
          """
-         return str('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in self.map_matrix]))
+         return str('\n'.join([''.join(['{:6}'.format(str(item)) for item in row]) for row in self.map_matrix]))
  
-     def __repr__(self):
-         """Internal representation
- 
-         Just use str for now.
-         """
-         return self.__str__()
- 
Add default value for matrix and methods to get columns and rows.
## Code Before:

from pixel import Pixel


class Pixelmap:

    def __init__(self, width, height):
        """Pixelmap constructor

        :param width: Width of map in pixels.
        :param height: Height of map in pixels.
        """
        self.width = width
        self.height = height
        self.map_matrix = [[0]*self.width for _ in range(self.height)]
        for row in range(self.height):
            for col in range(self.width):
                self.map_matrix[row][col] = Pixel()

    def __str__(self):
        """Human readable pixelmap description.
        Pretty much just the matrix.

        :return: Description of pixelmap.
        """
        return str('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in self.map_matrix]))

    def __repr__(self):
        """Internal representation

        Just use str for now.
        """
        return self.__str__()

## Instruction:
Add default value for matrix and methods to get columns and rows.
## Code After:

from .pixel import Pixel


class Pixelmap:

    def __init__(self, cols, rows, default_val=None):
        """Pixelmap constructor

        :param cols: Width of map in pixels.
        :param rows: Height of map in pixels.
        :param default_val: Default value for pixels.
        """
        assert cols >= 0, 'Invalid Pixelmap width'
        assert rows >= 0, 'Invalid Pixelmap height'
        self.cols = cols
        self.rows = rows
        self.map_matrix = [[0]*self.cols for _ in range(self.rows)]
        for row in range(self.rows):
            for col in range(self.cols):
                self.map_matrix[row][col] = Pixel(default_val)

    def num_cols(self):
        return self.cols

    def num_rows(self):
        return self.rows

    def __str__(self):
        """Human readable pixelmap description.
        Pretty much just the matrix.

        :return: Description of pixelmap.
        """
        return str('\n'.join([''.join(['{:6}'.format(str(item)) for item in row]) for row in self.map_matrix]))
