一:今日作业:

1、编写文件copy工具

old_file = input("请输入源文件的绝对路径:").strip()
new_file = input("请输入新文件的绝对路径:").strip()
with open(old_file, "rt", encoding="utf-8") as f1:
    with open(new_file, "wt", encoding="utf-8") as f2:
        info = f1.read()
        f2.write(info)
print("copy成功")
print("新文件路径为:", new_file)

2、编写登录程序,账号密码来自于文件

inp_user = input("请输入账号")
inp_psw = input("请输入密码")
with open(r"D:\工具\python\python代码练习\day11\aaa.txt",\
          mode="r",encoding="utf-8") as f:
    for line in f:
        user, password = line.strip().split(":")
        if inp_psw == password and inp_user == user:
            print("登陆成功")
            break
    else:
        print("登录失败,账号或密码错误")

3、编写注册程序,账号密码来存入文件

inp_user = input("请输入想注册的账号")
inp_psw = input("请输入密码")
with open(r"D:\工具\python\python代码练习\day11\aaa.txt", \
          mode="r", encoding="utf-8") as f:
    for line in f:
        user = line.strip().split(":")[0]
        if inp_user == user:
            print("账号名已存在,不能注册")
            break
    else:
        with open(r"D:\工具\python\python代码练习\day11\aaa.txt", \
                  mode="a", encoding="utf-8") as f:
            f.write("{}:{}\n".format(inp_user, inp_psw))
        print("注册成功")
 posted on 2020-03-13 20:30  wwwpy  阅读(177)  评论(0编辑  收藏  举报