在Python中退出程序的最安全的方法

时间:2015-12-24 07:37:47

标签: python python-3.x exception-handling

我在Python 3.5中编写一个简单的异常处理程序来检查用户输入是否是整数。我想知道如果输入无效,退出程序的标准做法是什么。

#Excersise working with number exceptions

user_in = input("Please enter a number: ")

try:
    val = int(user_in)
except ValueError:
    print("Invalid int")
    #exit statement here

print ("You entered: " + str(user_in))

0 个答案:

没有答案