title: How can I check if an input is on a certain line of a .txt file?
body: <p>I am creating a simple quiz program in python using text files to store the questions and answers. Is there a way to check if an input is on line 3 of a text file (for example).</p>
  <p>I have tried other methods that work but they check the whole file or the first three lines instead of just line 3. (Note: I am also getting an index error - string index out of range using the code below)</p>
  <p>Any help?</p>
  <p>Text file for answers:</p>
  <p><a href="https://i.stack.imgur.com/IcodE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IcodE.png" alt="enter image description here" /></a></p>
  <p>Text file for questions:</p>
  <p><a href="https://i.stack.imgur.com/KJd5C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KJd5C.png" alt="enter image description here" /></a></p>
  <p>Error:</p>
  <p><a href="https://i.stack.imgur.com/m7gI0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m7gI0.png" alt="enter image description here" /></a></p>
  <pre><code>def questions():
  
      question_answered = 0  # sets number of questions answered to zero
      lineq = 6  # sets the number of lines to output from questions.txt
      linea = 0  # sets the number of linea to read from answers.txt
      score = 0  # sets initial score to 0
  
      with open(&quot;questions.txt&quot;, &quot;r&quot;) as q:
          with open(&quot;answers.txt&quot;, &quot;r&quot;) as a:
              while question_answered != 3:
  
                  linea += 1
                  question_answered += 1
  
                  for i in range(lineq):
                      line = (q.readline())
                      print(line)
  
                  response = input(&quot;answer:&quot;)
  
                  check_line = a.readline()
  
                  if response in check_line[linea]:
                      score += 1
                      print(&quot;correct&quot;)
                      print(check_line[linea])
  
                  print(&quot;score:&quot;, score)
  
  
  questions() 
  </code></pre>