Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于打印的Python帮助_Python - Fatal编程技术网

关于打印的Python帮助

关于打印的Python帮助,python,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 se

我的问题是如何解决以下问题:我可以得到直线方程的正确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)`
您需要将(m,b)设置为等于方程式函数的输出:

(m, b) = equation(m, b)
print(m,'x +',b)

您还可以在各种形式中使用字符串格式

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


您也可以使用如下格式的打印:

print(f'{m}x + {b}')
字符串前面的f表示它已格式化,然后您可以像通常在大括号之间一样使用变量名

print("%dx + %d" % (m, b))
print(f'{m}x + {b}')