判断走哪一支
运行下面这段程序,填写它打印出来的结果。
def run(steps, stop_on_error=False):
"""steps 是一串退出码;返回 (跑了几条, 整个脚本的退出码)"""
ran = 0
last = 0
for rc in steps:
ran = ran + 1
last = rc
if stop_on_error and rc != 0:
return ran, rc
return ran, last
def ok(rc):
return rc == 0
steps = [0, 1, 0]
branch = ["成功支" if ok(rc) else "失败支" for rc in steps]
print("/".join(branch))
全部评论