title: How to find the smallest number in a text file (Python 2.5)
body: <p>So far, my code finds the largest number in a text file but it doesn't find the smallest number, when it's run the smallest number is still 0 while the largest is 9997.</p>
  
  <pre><code>    integers = open('numbers.txt', 'r') # opens numbers.txt
  
  largestInt = 0 # making variables to store the largest/smallest int
  smallestInt = 0
  
  # loop where we check every line for largest/smallest int
  for line in integers:
      while largestInt &lt;= line.strip():
          largestInt = line
      while smallestInt &gt;= line.strip():
          smallestInt = line
  
  # print results
  print "Smallest = ", smallestInt
  print "Largest = ", largestInt
  </code></pre>
  
  <p><code>numbers.txt</code> looks like:</p>
  
  <pre><code>6037
  -2228
  8712
  -5951
  9485
  8354
  1467
  8089
  559
  9439
  -4274
  9278
  -813
  1156
  -7528
  1843
  -9329
  574
  </code></pre>
  
  <p>and so on.</p>
  
  <p>What's wrong here? If I'm doing something wrong, or the logic is incorrect please correct me.</p>
  
  <p><code>EDIT</code></p>
  
  <p>I'd like to say thanks to @Martijn Pieters and @Gexos for for explaining what I'm doing wrong. I understand why my code works now!</p>
  
  <p>Final Code:</p>
  
  <pre><code>integers = open('numbers.txt', 'r') # opens numbers.txt
  
  largestInt = 0 # making variables to store the largest/smallest int
  smallestInt = 0
  
  # loop where we check every line for largest/smallest int
  for line in integers:
      if largestInt &lt;= int(line.strip()): # converted a string into an int
          largestInt = int(line.strip()) # made that int into largestInt
      if smallestInt &gt;= int(line.strip()): # converted a string into an int
          smallestInt = int(line.strip()) # made that int into smallestInt
  
  integers.close() # closes the file
  
  # print results
  print "Smallest = ", smallestInt
  print "Largest = ", largestInt
  </code></pre>
  
  <p>Results</p>
  
  <pre><code>Smallest =  -9993
  Largest =  9997
  </code></pre>