# 除0异常、值异常# 分开捕获,分开处理,或者统一处理""" file """try:
a =int(input('Please input a number: '))
b =int(input('Please input a number: '))
res = a/b
except ZeroDivisionError as reason:print('程序出错啦!\n错误原因是:'+str(reason))except ValueError as reason:print('程序出错啦!\n错误原因是:'+str(reason))else:print('程序正常运行啦!\n运行结果是:%d/%d=%d'%(a, b, res))""" file """try:
a =int(input('Please input a number: '))
b =int(input('Please input a number: '))
res = a/b
except(ZeroDivisionError, ValueError)as reason:print('程序出错啦!\n错误原因是:'+str(reason))else:print('程序正常运行啦!\n运行结果是:%d/%d=%d'%(a, b, res))""" shell """
Please input a number:10
Please input a number:0
程序出错啦!
错误原因是:division by zero
""" shell """
Please input a number:10
Please input a number:2.5
程序出错啦!
错误原因是:invalid literal forint()with base 10:'2.5'""" shell """
Please input a number:10
Please input a number:5
程序正常运行啦!
运行结果是:10/5=2