⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new_login_user.py

📁 python shi xian jian dan new_login_user
💻 PY
字号:
#!/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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -