【发布时间】:2021-09-20 15:01:41
【问题描述】:
尝试运行while 循环直到输入有效:
while True:
try:
print('open')
num = int(input("Enter number:"))
print(num)
except ValueError:
print('Error:"Please enter number only"')
continue #this continue is not working, the loop runs and break at finally
finally:
print('close')
break
如果输入了除数字以外的任何内容,则需要继续循环,但循环到达finally和breaks。
【问题讨论】:
-
据我了解,Final 总是在 try 块之后调用。 docs.python.org/3/tutorial/…
-
@Leo 谢谢。您的参考非常有用
标签: python python-3.x while-loop try-except continue