【问题标题】:password checker attemp 2密码检查器尝试 2
【发布时间】:2020-11-25 11:39:21
【问题描述】:

在我第三次尝试之后,如果我输入 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.")

【问题讨论】:

    标签: python password-checker


    【解决方案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.")
    

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 1970-01-01
      • 2014-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 2021-01-30
      • 2013-06-10
      相关资源
      最近更新 更多