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 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)`
解决方案
您还可以使用多种形式之一的字符串格式
print("{m}x + {b}".format(m=m, b=b))
print("{}x + {}".format(m, b))
或者
print("%dx + %d" % (m, b))
推荐阅读
- c# - 如何在 C# 中正确构建项目以包含 tessnet2?
- spring-boot - 如何 JUnit MapperToJsonString 类
- javascript - JavaScript 触发太多事件?
- java - Java 通用整数数据与原始 int 数据
- python-3.x - 如何使用 selenium 和 python 单击下拉菜单项?
- microsoft-graph-api - Microsoft Graph:如何从电子邮件中获取别名?
- r - 如何在回归模型中保留分类变量的某些值
- flutter - Flutter Webview Google OAuth
- r - RSelenium,Chrome,如何设置下载目录,文件下载错误
- django - Django Admin 编辑相关自定义用户模型