title: searching a 2d array in python - best method + indentation error
body: <p>I have created the following 2d array (list of lists) in Python:</p>
  
  <pre><code>#creating a 2d array (3 rows by 7 columns) and populating it with numbers
  matrix=[1,2,3,4,5,6,7],[8,9,10,11,12,13,14],[15,16,17,18,19,20,21]
  rows=len(matrix) #finding the max number of rows in the matrix, in this case 3
  columns=len(matrix[0]) #finding the max number of columns in each row, 7 in this case
  </code></pre>
  
  <p>I am trying to search for a specific element in the array (say the number 9), and then print "found", if found, and "not found", if not in the array, with the following code:</p>
  
  <pre><code>number=int(input("What number are you looking for?"))
  for i in range(rows):
        for j in range(columns):
          if matrix[i][j]==number:
            print("Found it!")
            break
  else:
    print("not found")
  </code></pre>
  
  <p>The output however, is erroneous: </p>
  
  <pre><code>&gt;&gt;What number are you looking for? 9
  &gt;&gt;Found it!
  &gt;&gt;not found
  </code></pre>
  
  <p>I have two questions: 1. could someone please explain identatation clearly, with reference to this problem and why the second "not found" always is output.
  2. Is there a better more efficient way to do this, without the use of numpy</p>
  
  <p>*note, this is not a duplicate, as I have searched the other entries and they don't quite deal with what I am explicitly asking. </p>
  
  <p>repl.it here:
  <a href="https://repl.it/IcJ3/3" rel="nofollow noreferrer">https://repl.it/IcJ3/3</a></p>
  
  <p>Someone just suggested an answer as below: (I had already tried this) </p>
  
  <p><a href="https://repl.it/IcJ3/5" rel="nofollow noreferrer">https://repl.it/IcJ3/5</a>
  Note, it doesn't work at all either:</p>
  
  <pre><code>number=int(input("What number are you looking for?"))
  for i in range(rows):
        for j in range(columns):
          if matrix[i][j]==number:
            print("Found it!")
            break
          else:
            print("not found")
  </code></pre>
  
  <p>Erroneous output, still!</p>
  
  <pre><code>What number are you looking for? 9
  not found
  not found
  not found
  not found
  not found
  not found
  not found
  not found
  Found it!
  not found
  not found
  not found
  not found
  not found
  not found
  not found
  </code></pre>