python字典模拟登陆
2015-08-16 20:37
615 查看
[code]db={} def newuser(): prompt='Login desired: ' while True: name=input(prompt) if name in db: prompt='name taken,try again' else: break; pwd=input('passwd: ') db[name]=pwd def olduser(): name=input('Login: ') pwd=input('passwd: ') realpwd=db.get(name) if pwd==realpwd: print('welcome back ',name) else : print('login incorrect') menu={'n':newuser,'e':olduser} def showmenu(): prompt=""" (N)ew User Login (E)xisting User Login (Q)uit Enter choice: """ done=False while not done: chosen=False while not chosen: try: choice=input(prompt).strip()[0].lower() except(EOFError,KeyboardInterrupt): choice='q' print('\nYour choice:[%s]' % choice) if choice not in 'neq': print('invalid option') else :chosen=True if choice=='q': break menu[choice]() if __name__=='__main__': showmenu()
相关文章推荐
- 再次开始学习python-Python Web实战 第一课
- Python多线程
- Pythonxy下载链接
- Pythonxy下载链接
- python修改EXCEL库,和爬虫库
- 递归实现汉诺塔问题(python)
- python解码编码要点
- Python将文本生成二维码
- Python生成验证码
- 浅谈五大Python Web框架
- 【Python基础】with as 语句
- 【Python相关文档】Postgresql数据库接口 - psycopg2,aiopy
- Python 发送邮件
- Python对xml的操作
- python抓取网页的一个小例子
- python操作MySQL
- Vim - python autocomplete plugin
- 关于selenium+python的googledirver和iedirver的配置
- python对拍程序
- Windows下为64位的python3.4.3安装numpy