python学习第一课
Posted raypy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python学习第一课相关的知识,希望对你有一定的参考价值。
第一步,实现 输入账号密码,显示账号欢迎:
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次锁定")
以上是关于python学习第一课的主要内容,如果未能解决你的问题,请参考以下文章