#小练习 异常

来源:互联网 发布:淘宝刷钻最新方法 编辑:程序博客网 时间:2024/05/16 04:40

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
原创粉丝点击