|
用字典创建一个平台的用户信息(包含用户名和密码)管理系统,新用户可以用与现有系统帐号不冲突的用户名创建帐号,已存在的老用户则可以用用户名和密码登陆重返系统。你完成了吗?建议程序框架为:
-
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 =
-
-
-
-
-
Enter the option
-
… …
-
-
if __name__ == '__main__':
-
login()
>>> user = {'a':123,'b':123,'c':123}
>>> def newusers(name):
if name in user.keys():
print('The name has exsited.Please try again')
name = input('please input your name:')
newusers(name)
else:
user[name]=input('Please set your password:')
print('Welcome',name)
>>> def oldusers(username, password):
if int(password) == user[username]:
print(username,'Welcome back!')
else:
print('login incorrect!')
>>> def login():
N = 'New User Login'
O = 'Old user Login'
E = 'Exit'
c = input('You are:New User Login or Old user Login or Exit? N/O/E:)')
if c == 'N':
name = input('Please input your name:')
newusers(name)
elif c == 'O':
username = input('name:')
password = input('password:')
oldusers(username, password)
else:
print('Bye!')
>>> if __name__=='__main__':
login()
You are:New User Login or Old user Login or Exit? N/O/E:)N
Please input your name:A
Please set your password:123
Welcome A
>>> user
{'c': 123, 'A': '123', 'a': 123, 'b': 123}
>>> if __name__=='__main__':
login()
You are:New User Login or Old user Login or Exit? N/O/E:)N
Please input your name:a
The name has exsited.Please try again
please input your name:q
Please set your password:234
Welcome q
>>> if __name__=='__main__':
login()
You are:New User Login or Old user Login or Exit? N/O/E:)O
name:a
password:234
login incorrect!
>>> if __name__=='__main__':
login()
You are:New User Login or Old user Login or Exit? N/O/E:)O
name:a
password:123
a Welcome back!
>>> if __name__=='__main__':
login()
You are:New User Login or Old user Login or Exit? N/O/E:)E
Bye!
|