明日方舟游戏素材开源项目资源库:新手快速上手指南
2026/5/7 11:36:44
第一题:
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