【发布时间】:2022-01-20 05:48:32
【问题描述】:
def interact():
while True:
try:
num = int(input("Please input an integer: "))
if (num % 2) == 0:
print ("{0} is even".format(num))
else:
print("{0} is odd".format(num))
num_two = int(input('Do you want to play again n/Y:'))
except:
if num_two == "y":
continue
finally:
print("Goodbye")
break
【问题讨论】:
-
你的 finally 块有一个中断。 finally 块总是运行,它总是中断。如果您不希望它每次都中断,请不要在 finally 块中设置中断。
标签: python if-statement try-catch except finally