""" 1.使用os和os.path以及函数的递归完成: 给出一个路径,遍历当前路径所有的文件及文件夹 打印输出所有的文件(遇到文件输出路径,遇到文件夹继续进文件夹) 2.使用加密模块及IO模拟登录功能,要求使用文件模拟数据库存储用户名和密码。 """ import os import os.path as path file_path_folder ="D:\\Vscode-Python\\code-py\\python2\\09_package\\test_module" def for_file(path1): for file in os.listdir(path1): path2 = path.join(path1,file) if path.isfile(path2): print(f"文件名:",{path2}) elif path.isdir(path2): for_file(path2) for_file(file_path_folder) import hashlib def encrytion(str): slat = "!!@@##" res = hashlib.md5(str.encode("utf-8")) res.update(slat.encode("utf-8")) return res.hexdigest() f = open("作业/3/a.txt",mode = "w") f.write("zhangsan") g = open("作业/3/b.txt",mode = "w") g.write("123") f=encrytion("zhangsan") g=encrytion("123") #模拟登录过程 username = input("username:") password =input("password:") def login(username,password): return True if encrytion(username) == f and encrytion(password) == g else False print("登录成功"if login(username,password) else "登录失败")