Python实现的用户登录系统功能示例
作者:毕加索的ma 时间:2021-07-02 03:38:18
本文实例讲述了Python实现的用户登录系统功能。分享给大家供大家参考,具体如下:
有N,E,Q三个选择,若选择Q或者中断,则系统退出。若其他选项,则持续让用户选择。
#!/usr/bin/env python
db = {}
def newuser():
prompt = 'login desired: '
while 1:
name = raw_input(prompt)
if db.has_key(name):
prompt = 'name taken, try another: '
continue
else:
break
pwd = raw_input('passwd: ')
db[name] = pwd
def olduser():
name = raw_input('login: ')
pwd = raw_input('passwd: ')
passwd = db.get(name)
if passwd == pwd:
pass
else:
print 'login incorrect'
return
print 'welcome back', name
def showmenu():##主函数名
prompt = """
(N)ew User Login
(E)xisting User Login
(Q)uit
Enter choice: """
done = 0 ##控制循环的控制器
while not done:
chosen = 0 ##控制循环的控制器
while not chosen:
try:
choice = raw_input(prompt)[0]
except (EOFError, KeyboardInterrupt):
choice = 'q'
print '\nYou picked: [%s]' % choice
if choice not in 'neq':##非neq继续小循环
print 'invalid menu option, try again'
else:
chosen = 1 ##跳出小循环
if choice == 'q': done = 1 ##跳出大循环
if choice == 'n': newuser()
if choice == 'e': olduser()
if __name__ == '__main__':
showmenu()
运行结果:
希望本文所述对大家Python程序设计有所帮助。
来源:http://www.cnblogs.com/paulwinflo/p/4936983.html
标签:Python,用户登录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JS阻止事件冒泡的方法详解
2023-09-10 08:57:36
JavaScript数值千分位格式化的两种简单实现方法
2023-08-31 22:59:43
CSS Sprites + 圆角[译]
2009-05-08 16:10:00
![](https://img.aspxhome.com/file/UploadPic/20095/8/01-11s.jpg)
ASP程序与SQL存储过程结合使用详解
2011-03-25 10:50:00
python实现发送QQ邮件(可加附件)
2023-01-21 18:37:00
![](https://img.aspxhome.com/file/2023/8/93778_0s.png)
Python+OpenCV目标跟踪实现基本的运动检测
2023-05-14 14:30:54
![](https://img.aspxhome.com/file/2023/7/80757_0s.jpg)
Win7下搭建python开发环境图文教程(安装Python、pip、解释器)
2023-08-09 00:46:47
![](https://img.aspxhome.com/file/2023/7/92527_0s.png)
asp如何制作一个简单的翻页程序?
2010-06-29 21:26:00
简单的文本内容处理工具
2010-01-28 12:31:00
从Vista地址栏到网站导航菜单
2009-09-08 12:35:00
![](https://img.aspxhome.com/file/UploadPic/20099/8/nav-62s.jpg)
Python安装图文教程 Pycharm安装教程
2022-06-19 20:03:05
![](https://img.aspxhome.com/file/2023/4/90434_0s.jpg)
网页设计标准尺寸
2008-06-15 15:21:00
常用CSS命名参考
2008-03-10 11:38:00
JupyterLab远程密码访问实现
2022-06-04 23:52:26
![](https://img.aspxhome.com/file/2023/9/89319_0s.png)
php投票系统之增加与删除投票(管理员篇)
2023-10-14 09:44:53
![](https://img.aspxhome.com/file/2023/0/55710_0s.png)
Jupyter notebook远程访问服务器的方法
2022-12-25 22:04:36
oracle中的视图详解
2009-12-22 11:48:00
php引用计数器进行垃圾收集机制介绍
2023-10-07 22:41:55
SQL Server日志文件总结及日志满的处理
2009-03-25 16:17:00
为您解读CSS优先级
2009-06-18 18:29:00
![](https://img.aspxhome.com/file/UploadPic/20096/18/01-66s.gif)