input: 
  def print_pattern(n: int) -> None:
      """
      Prints a pattern of '#' and spaces based on the given number n.
      For each pair of indices (i, j) in a grid of size n x n, if the sum of the indices
      is even, a '$' is printed; otherwise, a space is printed.
      The pattern is printed row by row.
      
      >>> print_pattern(7)
      ###  ###  
       ###  ###
      ###  ###  
       ###  ###
      ###  ###  
       ###  ###
      ###  ###  
      >>> print_pattern(2)
      ##
       #
      """
      for i in range(n):
          for j in range(n):
              if (i + j) % 2 == 0:
                  print('#', end='')
              else:
                  print(' ', end='')
          print()
  
output:     for i in range(n):
          for j in range(n):
              if (i + j) % 2 == 0:
                  print('#', end='')
              else:
                  print(' ', end='')
          print()