# 4.1:编写用户登录接口
# 4.2:编写程序实现用户注册后(注册到文件中),可以登录(登录信息来自于文件)
login = 1
while login:
Inp_zz = input('登录 1/注册 2: ').strip()
if Inp_zz == '1':
Inp_User = input('请输入用户: ').strip()
Inp_Pass = input('请输入密码: ').strip()
with open('a.txt',mode='rt',encoding='utf-8') as f3:
for g in f3:
username,password = g.strip().split(':')
if Inp_User == username and Inp_Pass == password:
print('登录成功')
login = 0
break
else:
print('用户或密码错误,请重新登录')
elif Inp_zz == '2':
with open('a.txt',mode='rt',encoding='utf-8') as f1:
Inp_rtu = input('用户: ').strip()
Inp_rtp = input('密码: ').strip()
for i in f1:
res1,_=i.strip().split(':')
if Inp_rtu.startswith(res1):
count = 1
break
else:
count = 2
if count == 1:
print('用于已存在,请重新注册')
continue
elif count == 2:
if len(Inp_rtu) != 0 and len(Inp_rtp) != 0:
with open('a.txt',mode='r+b') as f2:
f2.seek(0,2)
us='{}:{}\n'.format(Inp_rtu,Inp_rtp)
f2.write(us.encode('utf-8'))
print('注册成功,请重新登录')
else:
print('无效用户')
print()
break
else:
print('非法输入')
continue
#加油学,加油学,加油学
Python初学第一段代码
原创文章标签 Python初学第一段代码 文章分类 Python 后端开发
©著作权归作者所有:来自51CTO博客作者忽如一夜春风来呸的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
一段Python代码
一段Python代码
边缘像素 数组 ci -
一段代码
一段代码
一段代码 -
第一段nodejs代码
虚拟机端口转发 非常文档的运行
服务器 数据 端口转发 根目录 js