首页 > 解决方案 > 任何人都可以在python中的以下代码中检测到错误吗

问题描述

Q- 设计一个计算器,它可以正确解决除以下问题以外的所有问题:- 45*3=555, 56+9 = 77, 56/6 = 4

在此处输入代码

a = ("enter first number:")
b = ("enter second number:")
print(int(input(a)))
print(int(input(b)))
c = "enter your operator"
print(input(c))
if a==56 and b==9 and c == "+":
    print("77")
elif a==45 and b==3 and c=="*":
    print("555")
elif a==56 and b==6 and c=="/":
    print("4")
else:
    print("error! check your input") 

标签: pythoncalculator

解决方案


尝试更换:

a = ("enter first number:")
b = ("enter second number:")
print(int(input(a)))
print(int(input(b)))
c = "enter your operator"
print(input(c))

和:

a = int(input("enter first number:"))
b = int(input("enter second number:"))
c = input("enter your operator")

打印整数输入不会将它们存储到变量中。


推荐阅读