BC77 简单计算器
思路:
step1:分别计算加减乘除和错误输入;对应输出即可;
代码如下:
n = input()
# 加法:
if '+' in n:
n = n.split('+')
a = float(n[0])
b = float(n[1])
print('{:.4f}+{:.4f}={:.4f}'.format(a+0.00000001,b+0.00000001,a+b+0.00000001))
# 减法:
elif '-' in n:
n = n.split('-')
a = float(n[0])
b = float(n[1])
print('{:.4f}-{:.4f}={:.4f}'.format(a+0.00000001,b+0.00000001,a-b+0.00000001))
# 乘法:
elif '*' in n:
n = n.split('*')
a = float(n[0])
b = float(n[1])
print('{:.4f}*{:.4f}={:.4f}'.format(a+0.00000001,b+0.00000001,a*b+0.00000001))
# 除法:
elif '/' in n:
n = n.split('/')
a = float(n[0])
b = float(n[1])
if int(b) == 0:
print('Wrong!Division by zero!')
else:
print('{:.4f}/{:.4f}={:.4f}'.format(a+0.00000001,b+0.00000001,a/b+0.00000001))
# 错误:
elif ('+' not in n) and ('-' not in n) and ('*' not in n) and ('/' not in n):
print('Invalid operation!')