code: def print_matrix(matrix, msg=None):
      
      import math
  
      if msg is not None:
          print(msg)
  
      # Calculate the appropriate format width.
      width = 0
      for row in matrix:
          for val in row:
              width = max(width, int(math.log10(val)) + 1)
  
      # Make the format string
      format = '%%%dd' % width
  
      # Print the matrix
      for row in matrix:
          sep = '['
          for val in row:
              sys.stdout.write(sep + format % val)
              sep = ', '
          sys.stdout.write(']\n')
docs: Convenience function: Displays the contents of a matrix of integers.
  
      :Parameters:
          matrix : list of lists
              Matrix to print
  
          msg : str
              Optional message to print before displaying the matrix