0

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

"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.")
4

1 回答 1

1

这应该可以完成工作,您只是没有在第二个输入中检查密码(在 else 中),而且您正在检查循环顶部的密码,所以在第三次尝试时,您插入密码但添加了 1到 count 变量,所以你的 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.")
于 2020-08-05T11:10:23.330 回答