f= open('bbb')
result=f.read()
user_list=result.split('\n')#读取文件内容,以换行符分隔
user_dic={}
for user in user_list:
# 'abc,123'
username=user.split(',')[0]
password=user.split(',')[1]
# usrname,password=user.split(',')
# print(username)
# print(password)
user_dic[username]=password
# print(user_dic)
fw= open('bbb','a')
for i in range(3):
user=input('username:').strip().upper()
pd=input('password:').strip()
cpd=input('cpd:').strip()
if len(user) not in range(6,11) or len(pd) not in range(6,11):
print('账号/密码错误,6-10之间')
elif pd!=cpd:
print('两次输入密码不一致')
elif user in user_dic:
print('用户已存在')
else:
s = '%s,%s\n'%(user,pd)
fw.write(s)
print('注册成功')
break
else:
print('失败次数过多')