代码问题
x1 = float(input())op = input()
x2 = float(input())
try:
dic = {'+':x1+x2,'-':x1-x2,'*':x1*x2,'/':x1/x2}
print('%.2f'% dic)
except:
print('Calculation error')
代码运行
输入
1
+
2
输出
3.00
但是我想改成
输入
1+2
输出
3.00
代码该怎么修改 x = input()
x1 = float(x)
op = x
x2 = float(x)
try:
dic = {'+':x1+x2,'-':x1-x2,'*':x1*x2,'/':x1/x2}
print('%.2f'% dic)
except:
print('Calculation error') 请评最佳答案,谢谢
x = input()
x1 = float(x)
op = x
x2 = float(x)
try:
dic = {'+':x1+x2,'-':x1-x2,'*':x1*x2,'/':x1/x2}
print('%.2f'% dic)
except:
print('Calculation error') expr = input()
try:
res = eval(expr)
print(f'{res:.2f}')
except:
print('Calculation error') 学习编程中的Ben 发表于 2023-1-3 16:13
请评最佳答案,谢谢
你这个输入11+22呢? isdkz 发表于 2023-1-3 16:20
你这个输入11+22呢?
对哦
页:
[1]