第四次作业
2026/5/7 10:07:46 网站建设 项目流程

第一题:

import os def traverse_directory(path): for item in os.listdir(path): item_path = os.path.join(path, item) if os.path.isfile(item_path): print(item_path) elif os.path.isdir(item_path): traverse_directory(item_path)

第二题:

import hashlib import json import os USER_FILE = 'users.json' def hash_password(password): return hashlib.md5(password.encode('utf-8')).hexdigest() def register_user(username, password): if not os.path.exists(USER_FILE): users = {} else: with open(USER_FILE, 'r') as f: users = json.load(f) if username in users: print("用户名已存在。") return False users[username] = hash_password(password) with open(USER_FILE, 'w') as f: json.dump(users, f) print("注册成功。") return True def login_user(username, password): if not os.path.exists(USER_FILE): print("用户不存在。") return False if users[username] == hash_password(password): print("登录成功") return True else: print("密码错误。") return False

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询