Search code examples
pythonpassword-checker

password checker attemp 2


After my third attempt, if I input a k7e15 the output should be

"The password is correct"

but it is

"The system is disable"

what I need to change?

p = input("Enter a password: ")
count=0
while count<2:
    if p=="k7e15":
        print("The password is correct.")
        break
    else:
        p = input("The password is wrong,please try again:")
        count +=1
    if count>=2:
        print("The system is disable.")

Solution

  • This should do the job, you just weren't checking the password in the second input (inside the else), also you are checking the password at the top of the loop so at the third try, you insert the password but you add 1 to the count variable, so your count is equal to 3, and you jump to the if count>=2 which gives you back system is disable

    p = input("Enter a password: ")
    count=0
    while count<2:
        if p=="k7e15":
            print("The password is correct.")
            break
        else:
            p = input("The password is wrong,please try again:")
            if p=="k7e15":
                print("The password is correct.")
                break
            count +=1
        if count>=2:
            print("The system is disable.")