python 用字典创建一个平台的用户信息

版权声明: https://blog.csdn.net/lyw_321/article/details/79789466

用字典创建一个平台的用户信息(包含用户名和密码)管理系统,新用户可以用与现有系统帐号不冲突的用户名创建帐号,已存在的老用户则可以用用户名和密码登陆重返系统。你完成了吗?建议程序框架为:

def newusers():
    enter a name
    if the name is used in the system:
        enter again
    else:
        set the password
    … …
 
def oldusers():
    Enter the  username and password
    if password is right:  
        print(name, 'welcome back ')  
    else:  
        print('login incorrect')  
    … …
 
def login():
    option = '''
            (N)ew User Login 
            (O)ld User Login
            (E)xit
            """
     Enter the option
     '''
 
if __name__ == '__main__':  
     login()

代码:

option = {'AA':'11','BB':'22'}
def newusers():
    name=input('enter a  new name:')
    if name in option:
        newusers()
    else:
        option[name]=input('set the password:')
 
def oldusers():
    name=input('enter a name:')
    password=input('enter password:')
    if name in option and password in option.get(name):  
        print(name, 'welcome back ')  
    else:  
        print('login incorrect')  
 
def login():
    print('新用户注册')
    newusers()
    print('老用户登陆')
    oldusers()

 
if __name__ == '__main__':
     print(option)
     login()
     print(option)

效果:

{'AA': '11', 'BB': '22'}
新用户注册
enter a  new name:CC
set the password:33
老用户登陆
enter a name:CC
enter password:33
CC welcome back 
{'AA': '11', 'BB': '22', 'CC': '33'}
{'AA': '11', 'BB': '22'}
新用户注册
enter a  new name:CC
set the password:33
老用户登陆
enter a name:aa
enter password:12
login incorrect
{'AA': '11', 'BB': '22', 'CC': '33'}
{'AA': '11', 'BB': '22'}
新用户注册
enter a  new name:CC
set the password:33
老用户登陆
enter a name:AA
enter password:22
login incorrect
{'AA': '11', 'BB': '22', 'CC': '33'}



猜你喜欢

转载自blog.csdn.net/lyw_321/article/details/79789466