day3- python 注册
1 # 1、先把文件内容的账号密码放到list/字典 2 3 f = open('users') 4 result = f.read() 5 f.close() 6 user_list = result.split() # 7 user_dic = {} # 存放所有的用户 8 for user in user_list: 9 username,password = user.split(',') 10 user_dic[username] = password 11 12 fw = open('user','a') 13 for i in range(3): 14 user = input('username:').strip().upper() 15 pd = input('password').strip() 16 cpd = input('cpwd').strip() 17 if len(user) not in range(6,11) or len(pd) not in range(6,11) : 18 print('账号/长度不在6-10位之间') 19 elif pd != cpd: 20 print('两次输入密码不一致') 21 elif user in user_dic: 22 print('用户已经存在') 23 else: 24 user_dic[user] = password 25 s = '%s,%s\n' %(user,pd) 26 fw.write(s) 27 print('注册成功') 28 break 29 else: 30 print('失败次数过多!')