首页 > 解决方案 > 关于打印的 Python 帮助

问题描述

我的问题是如何解决以下问题:我可以获得直线方程的正确 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)`

标签: python

解决方案


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

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

或者

print("%dx + %d" % (m, b))

推荐阅读