五项一起对得上吗

👁️ 3 人浏览 💬 0 人评论 ❤️ 添加收藏

把这条路线算过的东西一次验完。运行下面这段程序:

def missing(need, have):
    return [s for s in need if s not in have]

def no_doc(funcs):
    return [n for n, d in funcs if not d]

def dry_run(steps, files):
    for i, (cmd, need) in enumerate(steps, 1):
        if need and need not in files:
            return i, need
    return 0, None

def bad_examples(examples, api):
    return [e for e, f in examples if f not in api]

need = ['是什么', '为什么', '怎么装', '怎么跑', '怎么测', '许可']
have = ['是什么', '怎么装', '怎么跑']
funcs = [('add', '把两个数加起来'), ('sub', None),
         ('div', '相除;除数为 0 时抛 ValueError'),
         ('mod', None), ('sqrt', None)]
steps = [('git clone https://example.com/calc.git', None),
         ('cd calc', None),
         ('pip install -r requirements.txt', 'requirements.txt'),
         ('python main.py', 'main.py')]
files = ['main.py', 'calc.py', 'README.md']
api = ['add', 'sub', 'div', 'mod', 'sqrt']
examples = [('add(2, 3)', 'add'), ('average([1,2,3])', 'average')]
i, _ = dry_run(steps, files)
ok = (len(missing(need, have)) == 3
      and len(no_doc(funcs)) == 3
      and i == 3
      and len(bad_examples(examples, api)) == 1
      and dry_run(steps, files + ['requirements.txt'])[0] == 0)
print(ok)
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论