设为首页 加入收藏

TOP

关于Python3.6下登陆接口的尝试
2017-12-29 06:07:11 】 浏览:120
Tags:关于 Python3.6 登陆 接口 尝试

编者按:
README:此代码为用户登陆界面,添加了寻求帮助选项。
1.学习了基本数据类型,string, int,以及while循环,continue, break, if, elif, else条件语句,“x".format(x)变量替代
2.上网搜的dictionary用法,由于用的是python3.6,老教程不太管用,尝试了2天方才悟出正确的增加键值用法,希望技术大牛留言给予更多启发!



dict_profile = {"Alex":"alex1234", "Bob":"bob123", "Cathy":"cathy1234",
                "David":"david12345", "Eva":"eva123"}
#Save the rightful username and password in the dictionary
black_list = { } #Create a list for not exist username
email = "send an email to our help desk for further solutions"
chance = 6 #After 3 valid trys the system will be locked
username = input("username:")
password = input("password:")
#password = getpass.getpass("password:")
while chance > 0:
    if username not in dict_profile.keys(): #Search for username in the profile
      black_list["{}".format(username)]="{}".format(password)
      username = input("The username does not exist, please try again:")
      chance = chance - 1
      if username in black_list.keys(): #Run a security check
        username = input("The username does not exist and has been locked, please try other combinations:")
        chance = chance - 2 # Deduct 2 chances to punish whoever abuses the system
    elif password != dict_profile.get(username,""): #Find the value of password to match with the username
      print("The password does not match the username, do you have problem with memorizing things?")
      customized_option = input("Y/N")
      if customized_option != "N":
        print("Please ask your partner or {}.".format(email))
        break
      else:
        password = input("Please enter your password with caution:")
        chance = chance - 1
    else:
        print("Welcome my lord {_name}! Please wait while login...".format(_name = username))
        break
if chance <= 0:
    print("The system is locked since you have too many incorrect entries!Please {}.".format(email))


登陆接口


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python datetime模块示例详解 下一篇Python 2.7中文显示与处理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目