密码检查器尝试 2

password checker attemp 2

第三次尝试后,如果我输入 k7e15,输出应该是

"The password is correct"

但它是

"The 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:")
        count +=1
    if count>=2:
        print("The system is disable.")

这应该可以完成工作,您只是没有在第二个输入中检查密码(在 else 内),您还在循环顶部检查密码,因此在第三次尝试时,您插入password 但你将 1 添加到 count 变量,所以你的计数等于 3,然后你跳转到 if count>=2 这让你返回 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.")