python简单用户管理模拟
来源:互联网 发布:mac识别不了u盘启动盘 编辑:程序博客网 时间:2024/05/21 22:49
python简单用户管理模拟
编辑一个脚本,简单模拟用户管理系统,使得其具有以下功能:
- 注册:若用户存在,直接报错”name 已经存在”,若用户不存在,将用户信息保存起来,显示”注册成功”;
- 登陆:若用户存在,判断密码是否正确,判断正确后输出”登陆成功”。若用户不存在,报错”name 不存在”;
- 注销:用户存在,验证密码,确认后删除用户信息;若不存在,报错”name 不存在”;
- 退出;
该脚本如下所示:
Account = {}def User_Exist(username): if username in Account: return True else: return Falsedef Passwd_right(username, password): if password == Account.get(username): return True else: return Falsedef Create(): while True: print "Please input username and password what you want to create !" New_user = raw_input("Username : ") if User_Exist(New_user): print "user is exist ! please input again !" else: break print "\n" New_password = raw_input("Password :") Account.setdefault(New_user, New_password) return "Account was created successfully !"def Login(): a = 0 while a < 3: print "Please input your username and password !" Username = raw_input("Username : ") Password = raw_input("Password : ") if User_Exist(Username): if Passwd_right(Username, Password): return "Login successfully !" else: print "Your username or password wrong !" else: print "This username is not exist !" a += 1 print "\n" else: return "The number of faults is bigger than 3 !"def Close(): a = 0 while a < 3: print "Please input username and password what you want to close !" Close_username = raw_input("Username : ") Close_password = raw_input("Password : ") if User_Exist(Close_username): if Passwd_right(Close_username, Close_password): Right = raw_input("Do you really want to close user this account ?(Y/N) ") if Right in "Yy": Account.pop(Close_username) return "Your account close successfully" elif Right in "Nn": return "Select None !" else: print "Please input Y or N !" print "\n" else: print "Your username or password wrong !" print "\n" else: print "This username is not exist !" print "\n" a += 1 else: return "The number of faults is bigger than 3 !"def Quit(): print "Goodbye !" print "\n" return exit(0)Select_dict = { "1": Create, "2": Login, "3": Close, "4": Quit}while True: print "\n" print """ welcome to xxx system There is some function you can select : 1. Create Account 2. Login 3. Close the Account 4. Quit""" Select = raw_input("Please input your select (1,2,3,4) :").strip() if Select in Select_dict.keys(): print Select_dict[Select]() else: print "Please input right select (1,2,3,4) !"
该脚本运行后的效果图如下图所示:
用户注册的效果图:
注册时可以看出,当注册成功后,显示用户创建成功。当用户存在时,显示用户已存在。
登陆时的效果图:
由登陆效果图可以看出,当用户登录时,用户不存在,显示用户不存在。当用户密码错误时,显示用户账号或密码错误。当错误次数超过三次时,显示失败的次数超过三次,然后退出登陆界面。当用户输入正确的账号密码时,显示登陆成功。
用户注销的效果图:
注销用户时,输入用户的账号和密码,选择是否确定删除这个用户,确认后删除这个用户,提示用户删除成功。
退出的效果图,选择后直接退出系统:
阅读全文
0 0
- python简单用户管理模拟
- python爬虫2-简单模拟用户登录
- Python--简单的用户管理系统
- Windows的用户管理中的用户模拟
- python用户管理系统
- 简单游戏场景用户模拟
- 简单的模拟用户登录
- Python模拟用户登陆网站
- Python模拟用户提交订单
- python selenium模拟用户登录
- JavaScript简单模拟内存管理
- Java简单用户管理系统
- ExtJS & GTGrid 简单用户管理
- springboot 简单用户管理模块
- python简单模拟数据库程序
- Python 模拟简单的queue
- python实现ZOJ1745(简单模拟)
- python简单模拟登陆详解
- putty上执行后台运行命令失效
- MySQL中查询后用查询结果当删除的判断条件,进行删除操作
- 【hihocoder】#1566 : 皇室成员的名字[Offer收割]编程练习赛25
- C语言形参和实参
- 输入与Module
- python简单用户管理模拟
- Tensorflow--多层神经网络
- 引用,指针,常量引用,常量指针,指针常量的区别
- 图像处理与计算机视觉基础,经典以及最近发展
- Linux Makefile的使用
- ES6的新增特性1
- iOS学习笔记-113.多线程12——NSOperation基础
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)
- python3对压缩文件处理