您的当前位置:首页正文

59-异常处理基础

来源:华佗小知识
try:   # 把有可能发生异常的语句放到try里执行
    n = int(input("number: "))
    result = 100 / n
    print(result)
except ValueError:
    print('invalid number')
except ZeroDivisionError:
    print('0 not allowed')
except KeyboardInterrupt:
    print('Bye-bye')
except EOFError:
    print('Bye-bye')

print('Done')