title: Using a loop to read a file and search for content, allow user to input multiple times to find a match
body: <p>I have a text file that contains 100 passwords. I want the user to be able to input their password, and have the program check the file. If the password entered matches then the program can end, but if the password does not match I want the to be able to try again.</p>
  <pre><code>pwEntry = input(&quot;Enter your password: &quot;)
  
  f1 = open('passwords.txt','r')
  for line in f1:
      if pwEntry in line:
          print(&quot;success&quot;)
      else:
          print(&quot;try again&quot;)
  f1.close()
  </code></pre>
  <p>I have tried a while loop, but it just says try again every time, even if I put in a correct password so its broken somehow.</p>
  <pre><code>f1 = open('passwords.txt','r')
  for line in f1:
      line = line.rstrip()
  pwEntry = 'x'
  while pwEntry not in f1.read():
      pwEntry = input(&quot;Enter your password: &quot;)
      if pwEntry in f1.readlines():
          print(&quot;Success&quot;)
      else:
          print(&quot;Try again&quot;)
  </code></pre>