python核心编程7.5答案ver1
来源:互联网 发布:java 图片上传 跨域 编辑:程序博客网 时间:2024/06/06 17:29
学习python中由于写到一半发现纯过程的话有点乱,学完对象之后再更新功能,没有实现时间戳,以及密码验证,非法字符验证也未添加....以后会持续更新
#!/usr/bin/env python
#coidng=utf-8import os
import sys
#初始化,后便测试manager
db = {'x':'y', 'a':'b', 'a':'d'}
def clear():
os.system("clear")
#清屏
def show():
clear()
for item in db.items():
print item
#manager 用于管理显示所有账户信息
def delete():
name = raw_input('please input the name you want to del:')
if not db.has_key(name):
print "the name you input not exists"
else:
del db[name]
#manager用于删除账户
def manager():
name = raw_input('login:')
if name == 'manager':
pwd = raw_input('passwd')
if pwd == '000000':
print "welcome manager"
while True:
print '''\
(S)how all information of usrs,
(d)el a usr,
(q)uit.'''
try:
choice = raw_input("please input your choice:").strip()[0].lower()
except (EOFError, KeyboardInterrupt):
choice = 'q'
if choice not in 'sdq':
print "invalid input, please try again"
else:
if choice == 's': show()
if choice == 'd': delete()
if choice == 'q': break
else:
print 'the password is not right'
else:
print 'the manager name is not right'
def usr():
name = raw_input('login:').lower()
if db.has_key(name):
pwd = raw_input('passwd:')
passwd = db.get(name)
if passwd == pwd:
print "welcome back", name
else:
print "passwd was not right(if you are a new usr try a new name)"
else:
s = raw_input("if you are a new user? print yes, else: print no:").strip().lower()
if s == 'yes':
pwd = raw_input('passwd:')
db[name] = pwd
print "welcome!!!", name
def showmenu():
prompt = '''\
(M)anager
(u)sr login
(Q)uit
Enter choice:'''
done = False
while not done:
chosen = False
while not chosen:
try:
choice = raw_input(prompt).strip()[0].lower()
except (EOFError, KeyboardInterrupt):
choice = 'q'
print "\nyou have [picked]: [%s] " % choice
if choice not in 'muq':
print 'invalid option, tru again'
else:
chosen = True
if choice == 'm':manager()
if choice == 'q':done = True
if choice == 'u':usr()
if __name__ == '__main__':
showmenu()
0 0
- python核心编程7.5答案ver1
- python核心编程,第六章,答案
- 《python核心编程》第二章练习答案
- python 核心编程 正则表达式部分答案
- python核心编程答案(第十六章)
- python核心编程第九章答案
- python核心编程-第六章习题答案
- python核心编程第13章答案
- Python核心编程第十章客后练习答案
- 《Python核心编程》第1章答案
- Python学习之《python核心编程》 第二章课后答案
- Python学习之《python核心编程》 第二章课后答案
- 《Python核心编程》中文第二版课后练习2.21答案
- 《Python核心编程》中文第二版课后练习3.8答案
- Python核心编程第15章正则表达式练习答案
- Python核心编程(第二版)2.21练习题答案
- python核心编程第七章习题答案(2)
- python核心编程第七章习题答案(3)
- uva 253 Cube painting
- IOS疯狂基础之屏幕旋转控制,获得当前方向
- 软件安装--telnet客户端和服务的安装
- 一季16集
- DG实验
- python核心编程7.5答案ver1
- Cocos2d-x 3.2 android实现原生对话框
- HDU 2108 Shape of HDU 判断多边形凹凸
- UML关系总结
- CRC中文维基百科
- 备忘录
- java的集合框架实现栈,队列
- 使用SharePoint自带的Workflow(二) 使用workflow
- 防御XSS的七条原则