import getpass #调用模块
U_L ={}#定义一个空字典defregister():
u_u =input('please enter username:')ifnot u_u:print('username not is null value')returnif u_u in U_L:print('This username has been registered please enter again')returnelse:
upass =input('password:')ifnot upass:print('The password cannot be empty,please re-enter it')returnelse:
U_L[u_u]=int(upass)deflogin():
u_u =input('please enter your username:')
upass =int(getpass.getpass('please enter you password:'))if U_L.get(u_u)== upass:print('login successfully')else:print('login failed')defchoice_memu():
cmds ={'0':register,'1':login}
promat ='''
Do you want to login or register?
(0)register
(1)login
(2)exit
please choice:'''while1:
choice =input(promat).strip()if choice notin['0','1','2']:continueif choice =='2':print('see you')print(U_L)break
cmds[choice]()if __name__ =='__main__':
choice_memu()
思路是当客户端注册用户时将用户输入的用户名和密码写入字典中就说用户注册成功当用户登录时如果字典中有相同的用户名和字典是就说用户登录成功反之向用户输出用户名或密码错误import getpass #调用模块U_L = {} #定义一个空字典def register(): u_u = input('please enter username:') if not u_u: print('username not is null value') return