python - 任何人都可以在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")
解决方案
尝试更换:
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")
打印整数输入不会将它们存储到变量中。
推荐阅读
- excel - 在 Excel 中创建一个在回答问题时向下移动的文本箭头
- oracle - Tibco Spotfire 桌面。信任自定义查询会破坏过滤器
- python - 在 Axes3D 中更改轴的位置
- python - 将抓取的数据附加到 CSV 文件
- asp.net-core - 当我的 API 需要授权令牌时,如何使用 Asp.Net Core 2.0 的内存中 TestServer 类进行集成测试?
- rest - Yii2 Api - 使用 Oauth 对用户和网站进行身份验证?
- android - 如何添加自增ID?
- postgresql - pgcrypto 在日志中保持可见的私钥?
- django - 尝试优化管理站点时出现“模型块已注册”错误
- android - 当相机到达标记上方时,如何在谷歌地图 v.3 中打开标记的标题?