循环跑了几次
运行下面这段程序,填写它打印出来的结果。
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
files = ["a.txt", "b.txt", "c.txt", "d.txt"]
rcs = [0, 0, 1, 0]
ran, code = run(rcs)
print(str(len(files)) + "/" + str(ran) + "/" + str(code))
全部评论