码迷,mamicode.com
首页 > 编程语言 > 详细

python学习第一课

时间:2018-09-09 18:05:47      阅读:177      评论:0      收藏:0      [点我收藏+]

标签: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次锁定")

 

python学习第一课

标签:amp   实现   span   dict   账号密码   +=   一课   break   style   

原文地址:https://www.cnblogs.com/RayPy/p/9614016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!