title: setting the first line read from a file if it is an int, as the end limit of a for loop in python
body: <p>Currently learning python, what I need to do is set the limit of a for loop equal to the int version of the first item read in a file</p>
  
  <p>for example:
  if a file contains the list:
  10
  1
  2
  3
  4
  ...</p>
  
  <p>I want the first line which contains 10, as the end limit for a for loop.
  or maybe there is another way to accomplish this, that would also be appreciated.</p>
  
  <p>here is what i have code:</p>
  
  <pre><code>otherFile = input("Do you have a file to open? (Y/N): ")
  
  while(otherFile == 'Y' or otherFile == 'y'):
  
      totalSum = 0
  
      try:
          with open(input("which file would you like to open? "), "r") as file:
              for line in file:
                  totalSum += int(line)
                  print(line, end="")
              print()
              print("Total Sum is: ", totalSum)
  
      except FileNotFoundError:
         print("File name invalid, Please enter valid name.")
         print()
  
      except ValueError:
         print("Invalid data type within file.")
  
      otherFile = input("Do you have another file to open? (Y/N): ")
  
  print("Goodbye")
  </code></pre>
  
  <p>I tried to read only the first line and turning that into an int, then setting it to limit but it did not work, i show that below:</p>
  
  <pre><code>        with open(input("which file would you like to open? "), "r") as file:
              numLines = int(file.readline())
              for line in numLines: &lt;---------- #what I tried
                  totalSum += int(line)
                  print(line, end="")
              print()
              print("Total Sum is: ", totalSum)
  </code></pre>