Python 练手D01

2017-12-16  本文已影响0人  Raphael_R

登录程序

import getpass
import json

user_info={"raphael":"pswdraphael","lisa":"lisalisa"}
wrong_name={}
confirm =0
print("请输入用户名及密码,任意位置按‘Q’退出")
while confirm==0:
    name=input("Name:")
    if name.lower() == "q":
        break
    password = getpass.getpass("Password:")
    if password.lower() =="q":
        break
    if name not in wrong_name.keys():
        wrong_name[name]=3
    while wrong_name[name] != 0:
        if name == user_info.keys():
            if password == user_info[name]:
                print("验证成功,进入系统")
                confirm=1
                break
        else:
            print("验证失败,您还有" + str(wrong_name[name]) + "次机会")
            wrong_name[name] -=  1
            break
    else:
        print("多次错误,您已被锁定")
        continue
else:
    print("您好,有什么可为您服务?")

上一篇下一篇

猜你喜欢

热点阅读