2020python练习六
程序员文章站
2022-07-06 12:38:59
2020python练习六 @2020.3.13 #1、编写文件copy工具 #2、编写登录程序,账号密码来自于文件 #3、编写注册程序,账号密码来存入文件 ......
2020python练习六
@2020.3.13
#1、编写文件copy工具
src_file=input('源文件路径>>: ').strip() dst_file=input('源文件路径>>: ').strip() with open(r'{}'.format(src_file),mode='rt',encoding='utf-8') as f1,\ open(r'{}'.format(dst_file),mode='wt',encoding='utf-8') as f2: res=f1.read() f2.write(res)
#2、编写登录程序,账号密码来自于文件
inp_username=input('your name>>: ').strip() inp_password=input('your password>>: ').strip() # 验证 with open('user.txt',mode='rt',encoding='utf-8') as f: for line in f: # print(line,end='') # egon:123\n username,password=line.strip().split(':') if inp_username == username and inp_password == password: print('login successfull') break else: print('账号或密码错误')
#3、编写注册程序,账号密码来存入文件
name=input('your name>>: ') pwd=input('your name>>: ') with open('db.txt',mode='at',encoding='utf-8') as f: f.write('{}:{}\n'.format(name,pwd))