您的位置:首页 > 编程语言 > Python开发

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

2018-04-02 15:07 316 查看
用字典创建一个平台的用户信息(包含用户名和密码)管理系统,新用户可以用与现有系统帐号不冲突的用户名创建帐号,已存在的老用户则可以用用户名和密码登陆重返系统。你完成了吗?建议程序框架为:
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'}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐