`
woxiaoe
  • 浏览: 276590 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

Python小例子-在控制台下模拟用户登录

阅读更多

python核心编程的一个例子,主要是字典的应用

'''
    小e
    在控制台下模拟用户登录
'''
users = {}
def register():
    while True:
        user = input("用户名:")
        if user in users:
            print('已存在该用户')
            continue
        else:
            passw = input('密码:')
            users[user] = passw
            print('注册成功 你的用户名%s\t密码%s'%(user,passw))
            break
def login():
    user = input('用户名:')
    if user not in users:
        print('不存在的用户')
    else:
        passw = input('密码:')
        if users[user] == passw:
            print('登录成功,欢迎你%s'%user)
        else:
            print('登录失败')
def showMenu():
    title = '''
        (R)用户注册
        (L)用户登录
        (E)用户退出
        选择:
        '''    
    while True:
        choice = input(title).strip()[0].lower();
        if choice not in 'rle' :
            print('输入有误')
        else:
            if(choice == 'r'):
                register()
            if(choice == 'l'):
                login()
            if(choice == 'e'):
                exit()
if __name__ == '__main__':
    showMenu()    
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics