【发布时间】:2014-10-29 20:10:18
【问题描述】:
continue = True
while continue:
try:
userInput = int(input("Please enter an integer: "))
except ValueError:
print("Sorry, wrong value.")
else:
continue = False
对于上面的代码,我如何能够捕获特定的ValueError?我的意思是如果用户输入一个非整数,我会打印出"Sorry, that is not an integer."。但是如果用户输入是空输入,我会打印出"Empty Input."。
【问题讨论】:
标签: python input try-catch except