← 返回题库
中级

构建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}
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码