Python 循环获取密码[重复]

问题描述 投票:0回答:1

抱歉我的英语不好,但我有一个问题

我想在 anaconda3 中对 python 进行简单的密码检查

现在我需要一个循环,当密码正确时最终停止,如果不正确,他打印 “密码错误”并再次询问。 这应该在 EnterPasswort 函数中,因为我稍后会再次需要它。

感谢您的帮助:)

也许有人有一个想法,密码只需尝试五次,然后就会锁定 5 分钟。 当没有人对此有答案时没问题,但这将是一个巨大的奖励。

python loops passwords spyder anaconda3
1个回答
0
投票
tries = 0#this will be the counter variable that will determin how much times 
#we tried the password
password = input("choose a password: ")#lets user choos password
while tries < 5:#while he tried less than five times
    sign_in = input("what is your password?")#ask the passowrd
    if sign_in == password:#if sighn in which is what user said = to password which is the passowrd say signed in
        print("signed in succesfully")
        break
    else:#if not 
        if tries >= 4:#if he trie to much times
            print("you tried signing in to many times!")# tell him and block
            break
        else:#if not tell him and loop goes again
            print("wrong password trie again")
            tries += 1 #or tries = tries + 1#calculte how uch he tried and loop again
© www.soinside.com 2019 - 2024. All rights reserved.