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')

你可能感兴趣的:(59-异常处理基础)