标签:amp 实现 span dict 账号密码 += 一课 break style
第一步,实现 输入账号密码,显示账号欢迎:
username = input("username :") password = int(input("password :")) print("welcome ",username,"!!!!!!!!!")
第二步,判断账号密码是否正确:
userlist1=["a",123] username = input("username :") password = int(input("password :")) if (username == userlist1[0]) & (password==userlist1[1]): print("welcome ",username,"!!!!!!!!!") else:print("erro")
第三步,利用表,判断账号是否存在,且密码正确:
dict = {‘a‘: 123, ‘b‘: 234}; username = str(input("username :")) password = int(input("password :")) if (dict.__contains__(username)) & (password == dict.get(username)): print("welcome ", username, "!!!!!!!!!") else: print("erro")
第四步,限制只能输入三次:
dict = {‘a‘: 123, ‘b‘: 234}; count=0 while count<3 : username = input("username :") password = int(input("password :")) if (dict.__contains__(username)) & (password == dict.get(username)): print("welcome ",username,"!!!!!!!!!") break else: print("您已输入错误",count+1,"次,输入错误3次锁定") count += 1
第五步,限制同一账号,只能输入错误3次,超出退出程序:
dict = {‘a‘: 123, ‘b‘: 234}; count=0 errolist=[] while count<3 : username = str(input("username :")) errolist.append(username) password = int(input("password :")) if ( dict.__contains__( username) ) & (password==dict.get(username)): print("welcome ",username,"!!!!!!!!!") break else: print("您已输入错误",errolist.count(username),"次,输入错误3次锁定") count = errolist.count(username)
第六步:限制同一账号,只能输入错误3次,限制所有错误5次,超出退出程序:
dict = {‘a‘: 123, ‘b‘: 234,‘c‘:456}; count=0 errolist=[] blacklist=[] while count<5 : username = str(input("username :")) errolist.append(username) password = int(input("password :")) if (blacklist.count(username)<3): if ( dict.__contains__( username) ) & (password==dict.get(username)): print("welcome ",username,"!!!!!!!!!") break else: print("您已输入错误",errolist.count(username),"次,输入错误3次锁定") blacklist.append(username) count +=1 print(count) if (count == 5) : print("您尝试错误5次,程序将退出") break else:print("您已输入错误3次锁定")
标签:amp 实现 span dict 账号密码 += 一课 break style
原文地址:https://www.cnblogs.com/RayPy/p/9614016.html