我正在做一个 python 课程,他们建议在 while 循环中使用 try 和 except 块,以便不断请求输入,直到满足条件。直觉上我觉得在“ except”块中再次调用该函数会更短,如下所示:
def exceptiontest():
try:
print(int(input("number 1: "))+int(input("number 2:")))
except:
print("a mistake happened")
exceptiontest()
exceptiontest()
Run Code Online (Sandbox Code Playgroud)
当我在论坛上询问课程时,我得到的答复是不一样。我现在有点困惑。有谁可以帮我澄清一下吗?提前致谢!