new_login_user.py

来自「fibonacci zi ding yi」· Python 代码 · 共 65 行

PY
65
字号
#!/usr/bin/env python
import sys
db={}

def newuser():
    prompt='name:  '
    while True:
        name=raw_input(prompt)
        if db.has_key(name):
            prompt='name taken ,try another'
            continue
        else:
            break
    pwd=raw_input('password:  ')
    db[name]=pwd

def userload():
    prompt='welcome to load in\n'
    promptn='Enter name:'
    promptp='Enter password'
    valid=False
    count=3
    while count>0:
        user_name=raw_input(promptn)
        user_pwd=raw_input(promptp)
        if (user_name,user_pwd) in db.iteritems():
            print prompt,
            break
        if not valid:
            print"warning-->the name and the password are wrong you have three chance to login"
            w_o_n=raw_input('whether to continue : (y|n)' )
            if w_o_n=='n':
                break
            count-=1
            continue
        else:
            break
def showmenu():
    prompt="""
 (N)ew user login
 (E)xiting user login
 (Q)uit
Enter your choice:"""
    done=False
    while not done:
        chosen=False
        while not chosen:
            try:
                choice=raw_input(prompt).strip()[0].lower()
            except (EOFError,KeyboardInterrupt,IndexError):
                choice='q'
                print'\n you picked:[%s]' % choice
            if choice not in 'neq':
                print'invaild option ,try again'
            else:
                chosen=True
        
        if choice=='q': done=True
        if choice=='n': newuser()
        if choice=='e': userload()


if __name__=='__main__':
    showmenu()
        

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?