一:今日作业:
1、编写文件copy工具
o_path = input('原文件的路径:')
n_path = input('新文件路径:')
with open(r'{}'.format(o_path),mode='r',encoding='utf-8') as f1,
open(r'{}'.format(n_path),mode='w',encoding='utf-8') as f2:
res = f1.read()
f2.write(res)
2、编写登录程序,账号密码来自于文件
user = input('请输入账号:')
pwd = input('请输入密码:')
with open('1.txt',mode='r',encoding='utf-8') as f:
res = f.readlines()
for line in res:
user1,pwd1 = line.strip().split(':')
if user1 == user and pwd1 == pwd:
print('登陆成功')
break
else:
print('登陆失败')
3、编写注册程序,账号密码来存入文件
while True:
user = input('请输入账号:')
if user.strip():
pwd = input('请输入密码:')
pwd2 = input('再次确认密码:')
if pwd == pwd2:
with open('wcwgw_fuben.txt',mode='a',encoding='utf-8') as f:
f.write('
{}:{}'.format(user,pwd))
print('注册成功')
break
else:
print('两次密码不一致')
else:
print('用户名格式不正确')