0

我的问题是如何解决以下问题:我可以获得直线方程的正确 m 和 b 值,但是如何以该格式打印它。

`import math
m=0
b=0
point1X = int(input("Input the first x value of a point in the line...."))
point1Y = int (input("Input the first y value of a point in the line...."))

point2X = int(input("Input the second x value of a point in the line...."))
point2Y = int (input("Input the second y value of a point in the line...."))


def equation (m,b):
    m = (point2Y-point1Y)/(point2X-point2Y)
    b = point1Y - (m*point1X)
    return (m,b)
print (equation(m,b))
print (m,'x''+',b)`
4

3 回答 3

1

您还可以使用多种形式之一的字符串格式

print("{m}x + {b}".format(m=m, b=b))
print("{}x + {}".format(m, b))

或者

print("%dx + %d" % (m, b))
于 2020-04-12T01:24:56.100 回答
0

您还可以使用这样的格式化打印:

print(f'{m}x + {b}')

字符串前面的 f 表示它已格式化,然后您可以像通常在花括号之间一样使用变量名称。

于 2020-04-12T01:27:43.087 回答
0

您需要将 (m, b) 设置为等于方程函数的输出:

(m, b) = equation(m, b)
print(m,'x +',b)
于 2020-04-12T01:19:49.777 回答