中级
构建API Mock数据生成器
未完成
中级参考
代码结构已给出,请填写 ____ 处
def solve():
from pyodide.http import open_url
from io import StringIO
products_csv = open_url(____).read()
import random, json
random.seed(____)
def generate_mock(____):
result = {}
for field, spec in schema.items():
if spec['____'] == '____':
result[field] = random.randint(spec.get(____), spec.get(____))
elif spec['____'] == '____':
choices = spec.get(____)
result[field] = random.choice(____)
elif spec['____'] == '____':
result[field] = round(random.uniform(spec.get(____), spec.get(____)), ____)
elif spec['____'] == '____':
result[field] = random.choice(____)
return result
user_schema = {
'____': {'____':'____','____':____,'____':____},
'____': {'____':'____','____':['____','____','____','____']},
'____': {'____':'____','____':['____','____','____']},
'____': {'____':'____'},
}
for i in range(____):
print(____)
示例
输入
solve()
期望输出
mock[1]: {"id": 1825, "username": "alice", "role": "guest", "is_active": false}
mock[2]: {"id": 4013, "username": "bob", "role": "admin", "is_active": true}
mock[3]: {"id": 8936, "username": "alice", "role": "guest", "is_active": false}
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199