python练习:模拟用户登录场景,密码最多输入3次

#模拟登录,依次输入用户名、密码,最多三次机会

userd = ['Linda', '123456']
while 1:
    username = input("Please input the username:")
    if username in userd:
        break
    else:
        print("your username is wrong!")

count = 3
while 1:
    password = input("Please input the password:")
    if userd[1] == password:
        print("Login success!")
        break
    else:
        print("Your password is wrong, please try again!")
        count -=1
        if count == 0:
            print("The user is locked")
            break
        else:
            print("You have %d chances left" %count)
原文地址:https://www.cnblogs.com/lxyykl001/p/11189745.html