Python通过简单的文件读写,来实现注册登录

# -*- coding:utf-8 -*-
''''''
username = input('请输入您的姓名:')
password = input('请输入密码:')
with open('get_info.txt','w+',encoding='utf-8') as file:
    file.write('{}\n{}'.format(username,password))
   #file.write('%s\n%s'%(username,password)) 用着行代码就可以不用使用format函数,效果是一样的 print('注册成功!\n开始登录') i = 0 lis = [] while i<3: usn = input('请输入您的姓名:') pwd = input('请输入密码:') with open('get_info.txt','r+',encoding='utf-8') as f: for line in f: lis.append(line) if usn == lis[0].strip() and pwd == lis[1].strip():#strip函数,用于消除空格和换行符 print('登录成功!') break else: print('账号或者密码错误') i+=1

  

猜你喜欢

转载自www.cnblogs.com/xcq7314/p/10746567.html