title: Validating username/pswd from .txt file in python - unwanted looping
body: <pre><code>passwordAttemptLoop = 0
      print("You have chosen to login!\n")
      while passwordAttemptLoop == 0:
          usernameAttempt = input("Please print your username below\n")
          passwordAttempt = input("Please print your password below\n")
          for line in open("usrnmPswd.txt","r").readlines():
              loginDetails = line.split()
              if usernameAttempt == loginDetails[0] and passwordAttempt == 
  loginDetails[1]:
                  passwordAttemptLoop = passwordAttemptLoop + 1
                  startQuiz()
              else:
                  print("Your username and/ or password is incorrect! Please 
  try again!")
  </code></pre>
  
  <p>The code shown above is made as the login system of a quiz program I am trying to create. It is made to read lines (columns) of the usrnmPswd.txt file (where the usernames/passwords are stored). If the username/ password are correct, it should start the quiz by calling the function startQuiz(). If username and/ or password are incorrect, it will tell the user that it is incorrect and ask them to input their username/ password again (due to while loop). I am getting 2 problems with this code:</p>
  
  <p>1)The output looks like this if the username/ password are correct:
  <a href="https://imgur.com/oQW1Z5i" rel="nofollow noreferrer">https://imgur.com/oQW1Z5i</a></p>
  
  <p>I think this is checking each individual line and printing the incorrect usrnm/pswd message until it reaches the line where both username and password are correct.</p>
  
  <p>2)Similarly if username and/or password are incorrect, the output I get looks like this:
  <a href="https://imgur.com/Buwdw4z" rel="nofollow noreferrer">https://imgur.com/Buwdw4z</a></p>
  
  <p>I understand that the problem is the looping of the validation of username/password but as i am a beginner programmer, i do not know what code to use in order to fix it.</p>
  
  <p>Any help/ code would be much appreciated if you know how to make the incorrect username/password message be printed only once. Thanks</p>