#1、编写文件copy工具 ''' a = input('请输入您复制的文件名:') b = input('您将要复制的文件名:') with open(a,mode='rb') as file,\ open(b,mode='wb+') as file2: c=file.read() d=file2.write(c) print(f'您复制的文件{a},现在{b}文件的内容为{d}') ''' #2、编写登录程序,账号密码来自于文件 #用户登陆 import re '''用户登陆 a = input("请输入您的账号:") b = input("请输入密码:")
with open('static/c.txt',mode='r+') as c: while True: d = c.readline() e = a + ":" + b + '\n' if e == d: print("账号密码正确,登陆成功") exit(0) print(len(d)) if len(d) == 0: print('登陆失败') exit(1) ''' '''注册账号 a = input("请输入您要注册的账号:") b = input("请输入要注册的密码:") with open('static/c.txt',mode='r+') as c: while True: d = c.readline() f= d.split(':') if a == f[0]: print("账号已存在,请重新输入") exit(1) if len(d) == 0: e = a + ":" + b + "\n" c.seek(0,2) c.write(e) print('账号已注册成功') exit(0) ''' #面向对象 class zcdl(): def start(self): self.start1 = input('''请输入要选择的功能: 1.登陆账号 2.注册账号 :''') if self.start1 == '1': self.denglu() if self.start1 == '2': self.zhuce() def denglu(self): a = input("请输入您的账号:") b = input("请输入密码:")
with open('c.txt', mode='r+') as c: while True: d = c.readline() e = a + ":" + b + '\n' if e == d: print("账号密码正确,登陆成功") exit(0) if len(d) == 0: print('登陆失败') exit(1) def zhuce(self): a = input("请输入您要注册的账号:") b = input("请输入要注册的密码:") with open('c.txt', mode='a+') as c: c.seek(0, 0) while True: d = c.readline() f = d.split(':') if a == f[0]: print("账号已存在,请重新输入") exit(1) if len(d) == 0: e = a + ":" + b + "\n" c.seek(0, 2) c.write(e) print('账号已注册成功') exit(0)