def func():
try:
n1 = int(input("Please input the firest one:"))
n2 = int(input("Please input the secend one:"))
per = input("Please input + - * /")
result = 0
if per == '+':
result = n1 + n2
elif per == '-':
result = n1 - n2
elif per == '*':
result = n1 * n2
elif per == '/':
result = n1 / n2
else:
print('输入有误!!')
print('result is:', result)
with open(r'D:/aa.txt','w') as wstream:
wstream.write("本次运行结果是:{}".format(result))
except ZeroDivisionError:
print('You must input int type.')
except ValueError:
print('Must input int type')
func()
将结果写入D:/aa.txt里面
版权声明:本文为博主原创文章,未经博主允许不得转载。
Python
- 上一篇:Python处理字符串之间多个空格
- 下一篇:Python异常抛出