11 课后练习

#一:今日作业:
#1、编写文件copy工具
sorce_file = input('源文件路径').strip()
dist_file = input('目标文件路径').strip()
with open(r'{}'.format(sorce_file),mode='w',encoding='utf-8') as f1,\
open(r'{}'.format(dist_file),mode='r',encoding='utf-8') as f2:
for line in f2:
f1.write(line)



#2、编写登录程序,账号密码来自于文件
name= input('输入用户名').strip()
psd = input('输入密码').strip()
with open('info.txt',mode='r',encoding='utf-8')as info_f:
for line in info_f:
username,userpsd = line.strip().split(':')
if username== name and userpsd == psd:
print('登陆成功')
break
else:
print('登录失败')

#3、编写注册程序,账号密码来存入文件
reg_name = input('创建用户名')
reg_psd = input('输入密码')
with open('reg.txt',mode='a',encoding='utf-8') as rg_f:
rg_f.write('{}:{}\n'.format(reg_name,reg_psd))
 
#一:今日作业:
#1、编写文件copy工具
sorce_file = input('源文件路径').strip()
dist_file = input('目标文件路径').strip()
with open(r'{}'.format(sorce_file),mode='w',encoding='utf-8') as f1,\
open(r'{}'.format(dist_file),mode='r',encoding='utf-8') as f2:
for line in f2:
f1.write(line)



#2、编写登录程序,账号密码来自于文件
name= input('输入用户名').strip()
psd = input('输入密码').strip()
with open('info.txt',mode='r',encoding='utf-8')as info_f:
for line in info_f:
username,userpsd = line.strip().split(':')
if username== name and userpsd == psd:
print('登陆成功')
break
else:
print('登录失败')

#3、编写注册程序,账号密码来存入文件
reg_name = input('创建用户名')
reg_psd = input('输入密码')
with open('reg.txt',mode='a',encoding='utf-8') as rg_f:
rg_f.write('{}:{}\n'.format(reg_name,reg_psd))

猜你喜欢

转载自www.cnblogs.com/baozai168/p/12729033.html