您的位置:首页 > 编程语言 > Python开发

#小练习 异常 分类: python异常 python 小练习 2013-05-14 13:35 452人阅读 评论(0) 收藏

2013-05-14 13:35 543 查看


while True:

try:

m=input('Please input first namuber:')

n=input('Please input second namuber:')

res= m/n



#多个异常,建议此处使用Exception e;使用e打印详细异常信息

except (NameError,ValueError,EOFError,SyntaxError,ZeroDivisionError),e:

print 'wrong occurs:'

print e



#取消输入操作,引发raise自定义的异常

except KeyboardInterrupt:


raise Exception ('---KeyboardInterrupt---')

#以下内容,不允许用户取消输入数据操作



#print 'you can`t cancel it,pleas enter a number'

#pass

else:

print 'Your score is:',res

break
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐