title: Display number of attempts left for incorrect password, accept if user inputs correct Password
body: <p>I have begun my programming journey a week ago with zero previous knowledge of coding.
  I also watched video on how to post stack overflow question, so would love constructive feedback.</p>
  
  <blockquote>
    <p>Details:</p>
    
    <p>Language - Python</p>
    
    <p>Version - 3.8.3</p>
    
    <p>Editor - VS Code</p>
  </blockquote>
  
  <p>I am trying to write a program that takes input from user and checks if it is a valid password. If yes, it displays "Correct" and exits program, if incorrect, it shows number of attempts left, 3 in total, and asks for input again.</p>
  
  <p>I just reached <strong>WHILE</strong> loop portion in my tutorial and used that to make the program.</p>
  
  <pre><code>msg = input("What's the secret password: ")
  
  # Password attempt is 3 times, starts at 2, then 1 and ends when counter is 0
  num = 2  
  
  # bananas is the correct password
  while msg != "bananas":  
      if num == 0:
          print("Too many wrong attempts. You are locked out!")  # exhausted all 3 attempts, should print given message.
  
      else:
          print(f"Wrong Password! You have {num} chances left")  # password incorrect, display attempts left
          msg = input("What's the secret password: ")
          num = num - 1
  
  print("Correct") 
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>If I run it and give correct password straightaway or after 1-2 failed attempts, it runs as expected.
  But if I give wrong input all 3 times, it goes into the loop of displaying the message </p>
  
  <blockquote>
    <p>Too many wrong attempts. You are locked out!</p>
  </blockquote>
  
  <p>And prints it forever. I am unable to figure out, where to exit the loop so that it only displays the message once and exits the program.</p>
  
  <p>Kindly help with resolving the issue.</p>
  
  <p><a href="https://i.stack.imgur.com/y6gb3.jpg" rel="nofollow noreferrer">2 incorrect password, 1 correct in 3rd attempt</a></p>
  
  <p><a href="https://i.stack.imgur.com/by2ed.jpg" rel="nofollow noreferrer">all 3 incorrect attempts</a></p>