小编Cra*_*aka的帖子

对于异常程序,如果没有获得所需的输出,如何在使用 Python 尝试最多 3 次后退出程序?

对于异常程序,如果没有获得所需的输出,如何在使用 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)
Run Code Online (Sandbox Code Playgroud)

python exception

5
推荐指数
1
解决办法
487
查看次数

标签 统计

exception ×1

python ×1