title: Why my Python function doesn't return the result?
body: <p>I am trying to write a Python function which can return "True" or "False" in evaluating a magic square. A magic square is a matrix all of whose row sums, column sums and the sums of the two diagonals are the same. (One diagonal of a matrix goes from the top left to the bottom right, the other diagonal goes from top right to bottom left.)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>def isMagic(A3):
      dim = A3.shape[0] * A3.shape[1]
      construct = np.arange(1,dim+1)
      if A3.shape[0] == A3.shape[1]:
          exist = []
          for r in range(len(A3)):
              for c in range(len(A3)):
                  exist.append(A3[r,c] in construct)
          if all(exist):
              def all_same(items):
                  return all(x == items[0] for x in items)
              dig_1 = sum(np.diag(A3))
              dig_2 = sum(np.diag(np.fliplr(A3)))
              dig = all_same(np.array([dig_1, dig_2]))
              column = all_same(np.sum(A3, axis = 1))
              row = all_same(np.sum(A3, axis = 0).transpose())
              if all(dig, column, row):
                  return True
              else:
                  return False
  </code></pre>
  
  <p>Yet, when I try to test my code on one of the magic square, the function doesn't return any value:</p>
  
  <pre><code>test2 = np.matrix([[8, 1, 6],
                [3, 5, 7],
                [4, 9, 2]])
  isMagic(test2) # True
  </code></pre>
  
  <p>I wondered that if it was because the indentation? </p>