这是代码
while True:
try:
age = int(input("Enter your age"))
except ValueError:
print("Enter the age in integer")
continue
except ZeroDivisionError: #when trying to divide the age for an age groups
print("Age cannot be zero")
continue
else:
print("thank you!!")
break
finally:
print("ok! I am finally done")
Run Code Online (Sandbox Code Playgroud)
在输入中,对于年龄,我给出一个字符串(例如:wefervrsvr),因此它必须经过ValueErrorexcept 块中的 ,该块具有print函数和 thencontinue语句,该语句使程序的控制到达循环的顶部,因此它再次要求输入来自我们,但我在这里不明白的是,为什么最终会在控制跳转到顶部的 try 块之前执行,正如我在输出中看到的那样。