python的计算脚本:
求100 与 输入数字 的 商
num =int(input('number:'))
result=100 / num
========================
本次展示的是
number为非零数字
ctrl+c 和ctrl+d的异常演示
========================
脚本文件:
#注释内容,为优化掉部分,可以省略;
注意行的缩进.
try:
num =int(input('number:'))
result=100 / num
# print(result)
# print('Done')
# except ValueError:
# print ('输入内容无效,只接受数字')
# except ZeroDivisionError:
# print('0不能作为除数')
except (ValueError,ZeroDivisionError)as e:
print(e,'# 只可输入非零数字!!!')
# except KeyboardInterrupt:
# print('\nBye-bye')
# except EOFError:
# print('\nBye-bye')
except (EOFError,KeyboardInterrupt):
print('\n Bye-bye')
exit(101)#程序遇到exit将会退出,退出码是101
else:
print(result)
finally:
print('DONE')