python核心编程7.5答案ver1

学习python中由于写到一半发现纯过程的话有点乱,学完对象之后再更新功能,没有实现时间戳,以及密码验证,非法字符验证也未添加....以后会持续更新

#!/usr/bin/env python

#coidng=utf-8
import 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值