簡體   English   中英

密碼檢查器嘗試 2

[英]password checker attemp 2

第三次嘗試后,如果我輸入k7e15 ,則 output 應該是

"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 中),而且您正在檢查循環頂部的密碼,所以在第三次嘗試時,您插入密碼但添加了 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.")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM