【发布时间】:2021-09-19 05:59:49
【问题描述】:
对于异常程序,如果你没有得到想要的输出,如何在使用 Python 最多 3 次尝试后退出程序?
while True:
try:
x = int(input("Please enter a number: "))
break
#except Exception as e:
# print (e)
except ValueError:
print ("You have entered the non-numeric value. Enter the numerical value.")
except KeyboardInterrupt:
print ("\nYou have press Ctr+C.")
exit (1)
【问题讨论】:
-
除了主要问题,请保持缩进标准 - 大多数人使用 4 个空格 per PEP-8,但您在不同的地方使用了 9、3 和 4。