A function records each part of try, except, else and finally that it runs.
def run(x):
out = []
try:
out.append("t")
y = 10 / x
except ZeroDivisionError:
out.append("e")
return "".join(out)
else:
out.append("s")
finally:
out.append("f")
return "".join(out)
print(run(0), run(2))
What does the program print?
Log in to join the discussion.
Loading…