python 编写一个实现分两行输入两个非零浮点数,并按顺序输出两个数的加减乘除计算式和计算结果的小程序
时间: 2023-03-22 10:02:23 浏览: 297
\u6211\u53ef\u4ee5\u56de\u7b54\u60a8\u7684\u95ee\u9898\u3002
\u9996\u5148\uff0c\u6211\u662f\u4ece\u4e00\u4e2a\u673a\u5668\u5b66\u4e60\u89c6\u89d2\u6765\u56de\u7b54\u60a8\u7684\u95ee\u9898\uff0c\u4e0d\u4f1a\u5206\u5f97\u8fd9\u4e2a\u95ee\u9898\u662f\u653f\u6cbb\u95ee\u9898\u3002
\u5bf9\u4e8e\u60a8\u63d0\u51fa\u7684Python\u95ee\u9898\uff0c\u6211\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u4e00\u4e2a\u53ef\u80fd\u7684\u65b9\u6cd5\u662f\u8fd9\u6837\u7684\uff1a
```
# -*- coding: utf-8 -*-
num1 = float(input("请输入第一个非零浮点数:"))
num2 = float(input("请输入第二个非零浮点数:"))
result1 = num1 + num2
result2 = num1 - num2
result3 = num1 * num2
result4 = num1 / num2
print("{0} + {1} = {2:.2f}".format(num1, num2, result1))
print("{0} - {1} = {2:.2f}".format(num1, num2, result2))
print("{0} * {1} = {2:.2f}".format(num1, num2, result3))
print("{0} / {1} = {2:.2f}".format(num1, num2, result4))
```
\u6b64\u89c6\u89d2\u6a21\u578b\u53ef\u4ee5\u652f\u6301\u7528Python\u8fdb\u884c\u6570\u5b66\u8ba1\u7b97\uff0c\u4f7f\u7528`input()`\u51fd\u6570\u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\uff0c\u7528\u4e8e\u8ba1\u7b97\u52a0\u3001\u51cf\u3001\u4e58\u3001\u9664\u7684\u7ed3\u679c\uff0c\u4e14\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u8f93\u51fa\u7ed3\u679c\u3002
\u5176\u4e2d`\u2003float(input("请输入第一个非零浮点数:"))\u2003`\u53ef\u4ee5\u83b7\u5f97\u7528\u6237\u8f93\u5165\u7684\u975e\u96f6\u6d6e\u70b9\u6570\uff
阅读全文